Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 710
some_id Avatar asked Jul 25 '10 11:07

some_id


1 Answers

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

like image 146
Vladimir Avatar answered Sep 19 '22 16:09

Vladimir