PDA

View Full Version : IBAction question




alexandergre
Nov 23, 2009, 04:40 PM
How can I get the name of the button instead of its title?
ex: if you click on button1 they log will be "button1"

thanx!

.h
IBOutlet UIButton *button1, *button2,*button3,*button4,*button5,*button6,*button7,*button8;
-(IBAction)tapped:(id)sender;

.m
-(IBAction)tapped:(id)sender{

NSString *buttonNumber = [sender titleForState:UIControlStateNormal];
NSLog(@"%s",buttonNumber);

}



kainjow
Nov 23, 2009, 04:48 PM
if (sender == button1)
NSLog(@"button1");
else if (sender == button2)
...etc...

alexandergre
Nov 23, 2009, 04:54 PM
if (sender == button1)
NSLog(@"button1");
else if (sender == button2)
...etc...

thanx. :) works but it takes some time since I have 24 buttons.

icewing
Nov 23, 2009, 04:57 PM
Sheesh! There's got to be a better way... :eek:

kainjow
Nov 23, 2009, 05:19 PM
Well if you have 24 buttons, I believe you can use IB to set a tag for each button, although I don't have it installed at the moment. Then you can use sender.tag to more easily identify each button.