some_id
some_id

Reputation: 29886

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 when 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

Upvotes: 13

Views: 13852

Answers (1)

Vladimir
Vladimir

Reputation: 170829

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

Upvotes: 20

Related Questions