» Site Navigation |
|
|
» Advertisements |

Visit our friends over at The App Show! Steve and Dave produce a weekly show shining a light on the iPhone 2.0 software and the applications being developed by the amazing development community for the iPhone SDK!
|
» Online Users: 104 |
| 19 members and 85 guests |
| BenLevy3, blackyE, bugnote, bugzilla, detz, dicklacara, dougdawson, elektrobank, erotsppa, FetaBoy, freshking, hyang, lymeric, mohaqa, Moose, MrsReznor, rbmac, twentythree, vanb777 |
| Most users ever online was 207, 10-24-2008 at 09:29 AM. |
» Stats |
Members: 3,915
Threads: 5,620
Posts: 23,272
Top Poster: scottiphone (705)
|
| Welcome to our newest member, raysms |
|
 |
|
10-07-2008, 08:55 PM
|
#1 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 11
|
UIButton . [sender attributes] . Where are you?
On a Splash page (eg) , if I have two buttons on the xib file ,
One says 'Jack', the other says 'Jill'...
Is it possible to have both buttons point to the same class via the same IBAction, but to have the method within the class grab the differences (title, tag, etc) from the sender attributes ?
I tried a test with something like this but it's not working:
- (IBAction) buNavigate: (id) sender {
NSString *senderInfo = [sender self];
NSLog(@"Sender Info: %@", senderInfo);
}
This results in this (from the NSLog) :
Sender Info: <UIRoundedRectButton: 0x452650>
I'm hoping for something that will result in this:
Sender Info: Jack
Is there a certain [sender attribute] that can find the right info?
Any ideas or alternate suggestions?
Much thanks!
|
|
|
10-07-2008, 09:03 PM
|
#2 (permalink)
|
|
Mobile Geek
Join Date: Aug 2008
Location: Florida, USA
Posts: 265
|
Well, I suppose you could look at the sender's "title" if you want "Jack" or "Jill". Alternately, you could simply compare the id value itself, if you've saved a reference to the two buttons.
|
|
|
10-07-2008, 11:24 PM
|
#3 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
If you only have two buttons then use two action methods. That's almost always simplest. If you want you can have outlets for the two buttons and then compare sender against the values of those outlets. If you have a bunch of buttons then set the tags of those buttons in IB and check the tag in the action method.
|
|
|
10-08-2008, 12:11 AM
|
#4 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 11
|
Quote:
Originally Posted by rames44
Well, I suppose you could look at the sender's "title" if you want "Jack" or "Jill". Alternately, you could simply compare the id value itself, if you've saved a reference to the two buttons.
|
That's exactly what I'm looking for, but when I go with [sender title] or other variations I get an error when I run... do you know specifically how to grab the title?
Quote:
|
Originally Posted by PhoneyDeveloper
If you only have two buttons then use two action methods. That's almost always simplest. If you want you can have outlets for the two buttons and then compare sender against the values of those outlets. If you have a bunch of buttons then set the tags of those buttons in IB and check the tag in the action method.
|
I feel like I have too many buttons to give an IBAction to each one (the Jack and Jill was just an example), and the thought of trying to keep track of a bunch of tags sounds too crazy. I just have to believe there is an easier way.
I've opened up my .xib file as xml, I see all the different tags in there, but how can I access them?!?
+
Thanks to both of you for the help!
+
|
|
|
10-08-2008, 12:46 AM
|
#5 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
Um, don't look at the xml. The attachment shows how you set the tag in IB. Just pick some tags and set them in IB and read them in your code. Every view has a tag property and you can use viewWithTag to search a view hierarchy for a particular view.
Last edited by PhoneyDeveloper; 11-18-2008 at 07:32 PM.
|
|
|
10-08-2008, 01:21 AM
|
#6 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 11
|
Quote:
Originally Posted by PhoneyDeveloper
Um, don't look at the xml. The attachment shows how you set the tag in IB. Just pick some tags and set them in IB and read them in your code. Every view has a tag property and you can use viewWithTag to search a view hierarchy for a particular view.
|
My concern with using the tags is that if I have 300 different buttons things could get a bit crazy. I just used the "Jack and Jill" scenario as an example.
I looked in the XML bc/ [sender title] was crashing the app. Getting desperate!
(Very cool to add the attachment, thanks!)
|
|
|
10-08-2008, 09:35 AM
|
#7 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
300 buttons is hard to believe. I can see couple dozen, maybe. I don't know why you think that a button's title is more reliable for identifying it than a tag. They're both things you type into a little box in IB. You would have to have some kind of table or list in your app that holds 300 titles or 300 tags and somehow indicates the action to take when the button calls its action method.
|
|
|
10-08-2008, 09:57 AM
|
#8 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 11
|
Quote:
Originally Posted by PhoneyDeveloper
300 buttons is hard to believe. I can see couple dozen, maybe. I don't know why you think that a button's title is more reliable for identifying it than a tag. They're both things you type into a little box in IB. You would have to have some kind of table or list in your app that holds 300 titles or 300 tags and somehow indicates the action to take when the button calls its action method.
|
Thanks for sticking with me on this issue PDev...
I dont think a title is more reliable, just easier to work with, especially if I am working with a lot of buttons. I would rather be able to do something like this:
if ([sender title] == "Jack") { blah blah blah...}
than this:
if ([sender tag] == 47) { blah blah blah...}
I understand that I could grab the tag from the sender, and then I could even key the tag number with a title via NSDictionary or something, but then I would have to maintain a little database of tags and titles. There has to be a way to grab the title from the sender!
If I grab the [sender self] , for two separate buttons, I get different logs for each one:
<UIRoundedRectButton: 0x453c90>
<UIRoundedRectButton: 0x40d570>
So there must be different info sent from each button! But does it send the title? And can it be accessed?
|
|
|
10-08-2008, 10:12 AM
|
#9 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
What's wrong with this:
Code:
#define kJack 47
if ([sender tag] == kJack) { blah blah blah...}
This code won't work anyway, for more than one reason:
Code:
if ([sender title] == "Jack") { blah blah blah...}
If you're really in love with the titles then look at the UIButton.h file and see how you read them. titleForState, currentTitle, not just plain title. Where did you get that?
|
|
|
10-08-2008, 10:12 AM
|
#10 (permalink)
|
|
Senior Member
Join Date: Aug 2008
Posts: 197
|
I'd rather make different IBActions for each outlet. Then have each action call any common code.
|
|
|
 |
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|