Go Back   iPhone Dev SDK Forum > Development Forums > iPhone SDK Development

Featured Member Applications

TanZen ($0.99)

Endless Walls ($0.99)

Air Hockey ($0.99)

SUPER STRIKE - Motion Bowl ($0.99)

BarSlot ($0.99)

MeterRead ($0.99)

Colorblind Helper ($4.99)

gContacts ($1.99)

ProgCalc ($1.99)

Forex On The Go Lite (FREE)

HUE knewit! ($0.99)

Want your application to be advertised here?

» 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
Reply
 
LinkBack Thread Tools Display Modes
Old 10-07-2008, 08:55 PM   #1 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 11
Default 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!
nerdhappy is offline   Reply With Quote
Old 10-07-2008, 09:03 PM   #2 (permalink)
Mobile Geek
 
Join Date: Aug 2008
Location: Florida, USA
Posts: 265
Send a message via AIM to rames44 Send a message via Yahoo to rames44
Default

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.
rames44 is offline   Reply With Quote
Old 10-07-2008, 11:24 PM   #3 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

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.
PhoneyDeveloper is offline   Reply With Quote
Old 10-08-2008, 12:11 AM   #4 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 11
Default

Quote:
Originally Posted by rames44 View Post
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!
+
nerdhappy is offline   Reply With Quote
Old 10-08-2008, 12:46 AM   #5 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

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.
PhoneyDeveloper is offline   Reply With Quote
Old 10-08-2008, 01:21 AM   #6 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 11
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
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!)
nerdhappy is offline   Reply With Quote
Old 10-08-2008, 09:35 AM   #7 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

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.
PhoneyDeveloper is offline   Reply With Quote
Old 10-08-2008, 09:57 AM   #8 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 11
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
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?
nerdhappy is offline   Reply With Quote
Old 10-08-2008, 10:12 AM   #9 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

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?
PhoneyDeveloper is offline   Reply With Quote
Old 10-08-2008, 10:12 AM   #10 (permalink)
Senior Member
 
Join Date: Aug 2008
Posts: 197
Default

I'd rather make different IBActions for each outlet. Then have each action call any common code.
lapse is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Powered by vBadvanced CMPS v3.0.1

All times are GMT -5. The time now is 05:06 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0