Reputation: 77631
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
Upvotes: 1
Views: 920
Reputation: 57149
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.
Upvotes: 7
Reputation: 61228
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) ...
Upvotes: 3