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

alexandergre

macrumors member
Original poster
Jul 28, 2009
58
0
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
Code:
IBOutlet UIButton *button1, *button2,*button3,*button4,*button5,*button6,*button7,*button8;
-(IBAction)tapped:(id)sender;
.m
Code:
-(IBAction)tapped:(id)sender{

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

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Code:
if (sender == button1)
    NSLog(@"button1");
else if (sender == button2)
    ...etc...
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.