Can't pass arguments into @selector methods?

前端 未结 2 1035
[愿得一人]
[愿得一人] 2021-01-22 03:36

I\'m currently trying to use a UIButton titled \"X\" as a way to remove a Sprite from the view.

Basically, my code works so that when a Sprite is touched, a message is s

2条回答
  •  臣服心动
    2021-01-22 04:06

    You should do this in the Sprite class, so in the original class:

    -(void)spriteSelected:(Sprite *)sprite{
          [sprite youAreSelected];
    } 
    

    In the Sprite class:

    -(void)youAreSelected {
        [self.button addTarget:self action:@selector(removeMe:) forControlEvents: UIControlEventTouchDown];
    }
    
    -(void)removeMe:(id)sender {
        [self removeFromSuperView];
    }
    

提交回复
热议问题