开发者

perform:@selector using a method with parameters

I have a method hideButton

-(void) hideButton:(UIButton) *button {
[button setHidden:YES];
}

and I get a "can not use an object as parameter to a method" error.

I want to be able to give the button as a parameter to the method wh开发者_Go百科en calling this

[self performSelector:@selector(hideButton:smallestMonster1)
withObject:nil afterDelay:1.0];

How can this be done? as the above attempt doesnt work. I need to be able to give the button as a parameter or at least make the method aware of which button is calling to be hidden after 1 second.

Thanks


You can pass parameter to selector via withObject parameter:

[self performSelector:@selector(hideButton:) withObject:smallestMonster1 afterDelay:1.0];

Note that you can pass at most 1 parameter this way. If you need to pass more parameters you will need to use NSInvocation class for that.

Edit: Correct method declaration:

-(void) hideButton:(UIButton*) button

You must put parameter type inside (). Your hideButton method receives pointer to UIButton, so you should put UIButton* there

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜