views:

286

answers:

1

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

+6  A: 

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

Vladimir
Thanks. How is the hideButton method set to take the object as a parameter? If I try the above I get the cannot use object as parameter error/
alJaree
It's not clear what is the problem... hideButton method definition is ok and it should be called properly with my answer... in 1st parameter performSelector - you provide selector signature, in withObject - the object as a parameter to pass to selector.
Vladimir
Either way if I try hideButton(UIButton) button, I get an error, and if I try hideButton(UIButton) *button i get an error. I tried using (id) as well but the app crashes with unrecognized selector sent to instance error.
alJaree
Sorry, didn't notice that problem on the 1st time. see edit.
Vladimir
Thanks a lot. that works. :)
alJaree