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 02-16-2011, 02:55 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 5
Stalevar is on a distinguished road
Default How to get NSIndexPath at Button in cell

Hello everybody! I have a question.

I want to add Button with title "Edit" into cell.

UIButton *editButton;
editButton.frame = CGRectMake(..., ..., ..., ...);
[editButton addTarget:self action:@selector(editClicked
forControlEvents: UIControlEventTouchUpInside];
[cell.contentView addSubview:editButton]];

How to get NSIndexPath of cell when i click on editButton?

Thank you
Stalevar is offline   Reply With Quote
Old 02-16-2011, 09:05 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

I'd subclass UIButton and give it an indexPath property. Then, in your cellForRowAtIndexPath method, you would assign the property with the current indexpath. After you click the button, you now will know what the indexpath is since your button will have that new property.
smithdale87 is offline   Reply With Quote
Old 02-16-2011, 09:12 AM   #3 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Code:
- (void)editClicked:(UIButton *)button
{
   UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
   NSIndexPath *indexPath = [[self tableView] indexPathForCell:cell];
   ...
}
The first line might change depending on your view hierarchy.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-17-2011, 02:57 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 5
Stalevar is on a distinguished road
Default

Thank you very much. It has helped me.
Stalevar 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: 369
7 members and 362 guests
cpsclicker, jeroenkeij, Kirkout, PavelMik, teebee74, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

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