Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 04-27-2011, 09:25 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Justin24 is on a distinguished road
Default detecting buttons event

Hi everyone,
I have a simple question. I have created many buttons with different titles (and tags if it is useful) using addSubview:button, and addTarget-ed them all to one method. But I want to know which button exactly is sending the message. The method is like this:
-(IBAction)pressButtonid)sender{}
Am I going to get the message by [sender currentTitle] or what? It doesn't seem to be working with that method.
Thank you!
Justin24 is offline   Reply With Quote
Old 04-27-2011, 09:30 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Quote:
Originally Posted by Justin24 View Post
Hi everyone,
I have a simple question. I have created many buttons with different titles (and tags if it is useful) using addSubview:button, and addTarget-ed them all to one method. But I want to know which button exactly is sending the message. The method is like this:
-(IBAction)pressButtonid)sender{}
Am I going to get the message by [sender currentTitle] or what? It doesn't seem to be working with that method.
Thank you!
*hinthint You tagged your buttons, now use them.
Domele is offline   Reply With Quote
Old 04-27-2011, 09:38 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

if you have the reference of your object you can use

if(sender==myButton)

or as Doemele said, you can use tag if you setted it, like
Code:
-(IBAction)pressButton:(id)sender{
 UIButton *but = (UIButton*)sender;
 if(but.tag==0)
    //do something
}
__________________
dany_dev is offline   Reply With Quote
Old 04-27-2011, 09:40 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Justin24 is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
*hinthint You tagged your buttons, now use them.
-,- ok I do not know how to get the tag... sender.tag leads to a warning
Justin24 is offline   Reply With Quote
Old 04-27-2011, 09:43 AM   #5 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by Justin24 View Post
-,- ok I do not know how to get the tag... sender.tag leads to a warning
look what I posted
__________________
dany_dev is offline   Reply With Quote
Old 04-27-2011, 09:50 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Justin24 is on a distinguished road
Default

It worked perfectly Thank you guys!!
Justin24 is offline   Reply With Quote
Old 04-27-2011, 10:03 AM   #7 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Justin24 is on a distinguished road
Default

so just one more thing: how do I change the title of the button after addSubview? shall I remove it all then add it again? all the buttons displaying are already in one mutable array.
Justin24 is offline   Reply With Quote
Old 04-27-2011, 10:09 AM   #8 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you can just use the reference on the array, this is no related to addSubview.
__________________
dany_dev is offline   Reply With Quote
Old 04-27-2011, 10:28 AM   #9 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 8
Justin24 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
you can just use the reference on the array, this is no related to addSubview.
Thanks for your reply, but anyway I did it by removing them all and then adding them all again
Justin24 is offline   Reply With Quote
Reply

Bookmarks

Tags
uibutton

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



» Advertisements
» Online Users: 346
12 members and 334 guests
dansparrow, iOS.Lover, lorrettaui53, MikaelBartlett, Nobbsy, oztemel, pbart, PlutoPrime, samdanielblr, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,897
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:52 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0