views:

49

answers:

2

Hi All!

I have a view with several buttons that all have the same target and action.

At the moment the action is @selector(doSomething).

I need to be able to determine which button is pressed but I'm not sure of the best way to do this.

The method doSomething is declared as...

-(void)doSomething;

Is there a better way to declare this so I can get more info out?

Thanks for any help!

Oliver

+2  A: 

Target/action messages provide the sender as the argument. In your case, the button that called the message is the sender. You could ask it for its -tag (which you can set in IB) or you could name it as an outlet and test for equality: if (sender == myButtonOne) ...

Joshua Nozzi
+6  A: 

If you declare the method as

- (void)doSomething:(UIButton *)sender

with the corresponding selector @selector(doSomething:), then you can check the identity of the sender using either of the methods Joshua suggested.

Noah Witherspoon
Thanks!Worked a charm!
Fogmeister