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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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-23-2009, 04:02 PM   #1 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 49
Default indexPath.row causing problems

I have a table view that's filled with custom cells. I can populate the table just fine and even zebra stripe the table (using indexPath.row % 2). However, when I click on any of the cells, the app crashes. Here's my didSelectRowAtIndexPath code in my table view controller:
Code:
- (void) tableView: (UITableView *) tableView
didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
    NSLog(@"row clicked: %@", indexPath.row);
}
All I'm trying to do is spit out the row that was clicked. If row 0 is clicked, indexPath.row gives me "null". Any other visible row results in an EXC_BAD_ACCESS error. Any ideas why the indexPath gets hosed between creating the cell and clicking the cell?

Added:
Once I figure out which cell was clicked, I want to push a view controller. Each cell will have different info so it's important that I figure out which row it was. I've also got a standard UITableView elsewhere in the app that doesn't have this problem. If I jump into the setSelected: animated function in my custom cell, I can also tell when the cell was clicked (and get it's ID) but an unsure of how to push the view controller from there as self.navigationController isn't defined in a UITableViewCell. Which is the "better" way to push the view controller?

Last edited by chewbocka; 02-23-2009 at 04:06 PM.
chewbocka is offline   Reply With Quote
Old 02-23-2009, 08:03 PM   #2 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 49
Default

I figured it out, I started grabbing the actual cell instead of the row and that seems to work. There's some other info that has to be attached to the cell (such as ID, etc) but it's all good. I found an example using custom cells here.
chewbocka is offline   Reply With Quote
Old 02-24-2009, 07:46 AM   #3 (permalink)
iPhone Developer
 
Narender Mudgal's Avatar
 
Join Date: Dec 2008
Location: India
Age: 27
Posts: 155
Send a message via MSN to Narender Mudgal Send a message via Skype™ to Narender Mudgal
Post Hi

Quote:
Originally Posted by chewbocka View Post
I figured it out, I started grabbing the actual cell instead of the row and that seems to work. There's some other info that has to be attached to the cell (such as ID, etc) but it's all good. I found an example using custom cells here.
Did you tried without your NSLog statement wheather it is crashing or not.
????
Narender Mudgal is offline   Reply With Quote
Old 02-24-2009, 12:56 PM   #4 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 49
Default

Quote:
Originally Posted by Narender Mudgal View Post
Did you tried without your NSLog statement wheather it is crashing or not.
????
Yep, it went down regardless. Either way, I'm good now.
chewbocka is offline   Reply With Quote
Old 10-26-2010, 03:47 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 2
Default

actually your specifier is wrong. try

NSLog(@"row clicked: %i", indexPath.row)

that should work and tell you which row it is.
bigubosu is offline   Reply With Quote
Old 10-26-2010, 03:13 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
Default

you can also customize the cell without subclassing. you can just add whatever you want to table view cell's content view

Apple has a tutorial on this

Loading…
__________________
My Apps in AppStore
ZubiZubi is offline   Reply With Quote
Old 10-26-2010, 03:17 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
Default

here is the customized table/cells in my app based on the tutorial i posted above (each news headline is a cell here with title, details, image and pointer (hand picture))

__________________
My Apps in AppStore
ZubiZubi 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: 459
12 members and 447 guests
banatary70, darbsllim, Domele, dre, EdwardMichel, HowEver, ilmman, iOSguru, johnRambo, maryrobertson, Objective Zero, Oral B
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 157,853
Threads: 88,914
Posts: 379,297
Top Poster: BrianSlick (7,072)
Welcome to our newest member, banatary70
Powered by vBadvanced CMPS v3.1.0

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