IBAction question - MacRumors Forums
Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 23, 2009, 04:40 PM   #1
alexandergre
macrumors member
 
Join Date: Jul 2009
IBAction question

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);
	
}
alexandergre is offline   0 Reply With Quote
Old Nov 23, 2009, 04:48 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Code:
if (sender == button1)
    NSLog(@"button1");
else if (sender == button2)
    ...etc...
kainjow is offline   0 Reply With Quote
Old Nov 23, 2009, 04:54 PM   #3
alexandergre
Thread Starter
macrumors member
 
Join Date: Jul 2009
Quote:
Originally Posted by kainjow View Post
Code:
if (sender == button1)
    NSLog(@"button1");
else if (sender == button2)
    ...etc...
thanx. works but it takes some time since I have 24 buttons.
alexandergre is offline   0 Reply With Quote
Old Nov 23, 2009, 04:57 PM   #4
icewing
macrumors 6502
 
Join Date: Jun 2008
Location: St Louis
Sheesh! There's got to be a better way...
__________________
2012 15.4" MBP 9,1, 2.6 GHz Intel Core i7, 8 G Ram, High-Res Anti-Glare
icewing is offline   0 Reply With Quote
Old Nov 23, 2009, 05:19 PM   #5
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Mophie Juice Pack Plus (iPhone 5) Question - Mute Button Question JulesK iPhone Accessories 3 Mar 30, 2014 02:58 PM
Snow Leopard File Vault Question and Basic System Password Question & Time Machine? GordonGekko999 Mac Basics and Help 0 Oct 25, 2013 06:06 AM
Question for anyone who has seen or owns the pink ipod nano? Color deciding question. Pinkstiletto66 iPod 4 Apr 4, 2013 12:57 PM
Family Share Question, Upgrade Question, Argh head hurting.. Jazwire iPhone 1 Sep 14, 2012 12:19 AM
Time Capsule - Newbie Question Wifi Question Alper1234 Mac Peripherals 1 Jun 23, 2012 09:17 AM

Forum Jump

All times are GMT -5. The time now is 10:00 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC