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 09-16-2008, 12:05 AM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 15
dizy is on a distinguished road
Default action:@selector()

If i add a custom button to a tableViewCell and ...
[button addTarget:self action:@selector(infoButtonPressed) forControlEvents:UIControlEventTouchUpInside];

How can I pass arguments to the selector ?

I would like to know which row the button was pressed

TIA
dizy is offline   Reply With Quote
Old 09-16-2008, 09:25 AM   #2 (permalink)
h2h
Registered Member
 
Join Date: Aug 2008
Posts: 38
h2h is on a distinguished road
Default

Quote:
Originally Posted by dizy View Post
If i add a custom button to a tableViewCell and ...
[button addTarget:self action:@selector(infoButtonPressed) forControlEvents:UIControlEventTouchUpInside];

How can I pass arguments to the selector ?

I would like to know which row the button was pressed

TIA
Well you don't pass arguments, but you rather pick them up...

change your selector to:

infoButtonPressed:

and then you must implement in your controller the following function:

Code:
-(void)infoButtonPressed:(id)sender 
{
// here you can access the object which triggered the method
// for example you can check the tag value

NSLog(@"the tag value is: %d", [sender tag]);
}

hope this helps

greetings
h2h is offline   Reply With Quote
Old 09-16-2008, 09:50 AM   #3 (permalink)
New Member
 
Join Date: Aug 2008
Location: Ohio
Posts: 46
BoB3K is on a distinguished road
Default

So, you can't just pass arguments when using action:@selector() ?
__________________
BoB - Terminal Core Games
Current iPhone Apps: BloXoR . SpinDice
BoB3K is offline   Reply With Quote
Old 09-16-2008, 09:52 AM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 15
dizy is on a distinguished road
Default

Thanks h2h, that does help.

So I guess that means I have to first assign the button.tag to the row number first.

Is tag just a generic placeholder for passing Integers ?

What if I wanted to somehow pick up a specific object based on the row... or maybe a better question would be... what other methods/properties do you normally access via the sender ?



Quote:
Originally Posted by h2h View Post
Well you don't pass arguments, but you rather pick them up...

change your selector to:

infoButtonPressed:

and then you must implement in your controller the following function:

Code:
-(void)infoButtonPressed:(id)sender 
{
// here you can access the object which triggered the method
// for example you can check the tag value

NSLog(@"the tag value is: %d", [sender tag]);
}

hope this helps

greetings
dizy is offline   Reply With Quote
Old 09-16-2008, 01:31 PM   #5 (permalink)
h2h
Registered Member
 
Join Date: Aug 2008
Posts: 38
h2h is on a distinguished road
Default

Quote:
Originally Posted by dizy View Post
Thanks h2h, that does help.

So I guess that means I have to first assign the button.tag to the row number first.
Thats a good starting point, that's what I do to keep track of the cells, specifically since generally the row is related to the 'objectAtIndex' of an array as datasource...

Quote:
Originally Posted by dizy View Post
Is tag just a generic placeholder for passing Integers ?
right

Quote:
Originally Posted by dizy View Post
What if I wanted to somehow pick up a specific object based on the row... or maybe a better question would be... what other methods/properties do you normally access via the sender ?
Well this depends on what you want to do. The sender is a way to get access to the object which called the function ... and from there on it is up to your imagination

greetings
h2h is offline   Reply With Quote
Old 09-16-2008, 02:10 PM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 15
dizy is on a distinguished road
Default

Is there some generic (id) placeholder that I can use ?


Quote:
Originally Posted by h2h View Post
Well this depends on what you want to do. The sender is a way to get access to the object which called the function ... and from there on it is up to your imagination

greetings
dizy is offline   Reply With Quote
Old 11-07-2008, 03:38 AM   #7 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 20
hedfuc is on a distinguished road
Default

seems like there is no any
hedfuc is offline   Reply With Quote
Old 12-10-2009, 05:58 AM   #8 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 96
Dvdkite is on a distinguished road
Default

I just want to say thank you to h2h.

It works perfectly and it's so simple to implement.

the best and fast solution for the problem.

Thank you!!!!!!!

Greetings

David
Dvdkite is offline   Reply With Quote
Old 08-08-2010, 11:34 AM   #9 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 1
AsifB is on a distinguished road
Default pass annotation values to detail view

I have
- (MKAnnotationView *)mapViewMKMapView *)mV viewForAnnotationid <MKAnnotation>)annotation
{
........ some code ......

[rightButton addTarget:self
action:@selector(showDetails)
forControlEvents:UIControlEventTouchUpInside];

...... some code .....
}

- (void)showDetailsid)sender
{

MyDetailView *Second = [[MyDetailView alloc] initWithNibName:@"MyDetailView" bundle:nil];
[self presentModalViewController:Second animated:YES];

//I want to assign the annotation title to the details view

Second.label.text = ????

[Second release];

}

How can I do that?
AsifB 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



» Advertisements
» Online Users: 324
8 members and 316 guests
2Apps1Day, akacaj, Domele, michelle, SLIC, soohyun, Techgirl-52, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,886
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

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