Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newlearner

macrumors member
Original poster
Jul 30, 2009
37
0
india
I have 3 buttons in a single view. All three can be given the same IBAction. But how to know which button was pressed?

I tried implementing the following code:

Code:
-(IBAction)callAction:(id)sender {

UIButton *b=(UIButton *)sender;
NSLog(@"button pressed is : %d", [sender tag]);
}

But for all buttons, the answer is always 0.

Is there something I am missing here?

Or is there any other alternative?

Thanks
 
How to set the tag values? I looked under in the documentation for UIButton, but it doesnt have any mention for tags. Could you please guide me?
 
Read the docs for UIButton's superclass. Then that class's superclass.

But UIControl and UIView also dont mention about 'tag'.

Am sorry if it sounds silly, am not able to get the correct link for reading about it.

found it.

NSControl mentions it. Not UIControl.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.