I feel like this is an issue that requires special attention... my Google-fu is pretty good but I haven't been able to get anything useful.
This is the simplest thing, and yet I can't seem to figure out what the problem is with it.
I have a UITableView. It's a subview that my VC calls _form. I'm using it for styling purposes, not really to display data. It has 2 cells.
On a certain event, I'm trying to select a different cell, using selectRowAtIndexPath:animated:scrollPosition.
When I do this, it SIGABRTS.
A simple example:
- (IBAction)submitClicked:(id)sender
{
[_submit setTitle:@"Wha!?" forState:UIControlStateNormal];
NSIndexPath *row = [NSIndexPath indexPathWithIndex:0];
NSLog(@"%d", [[_form indexPathForSelectedRow] row]);
[_form selectRowAtIndexPath:row animated:YES scrollPosition:YES];
}
The button's title is changed, AND the table prints that the selected row is 0 or 1, but on trying to select the desired cell, it breaks:
2012-03-09 21:57:39.905 <omitted>[16329:207] 0
2012-03-09 21:57:39.908 <omitted>[16329:207] *** Assertion failure in -[NSIndexPath row], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableViewSupport.m:2598
(gdb)
My assumption is that this implies something is wrong with how my table is configured, but I'm not sure what. Selecting the cells in the table normally (clicking it) is working, as indicated by the expected response in my tableView:didSelectRowAtIndexPath. Everything else works fine with how I have this set up, except this.
(Also, I other people replying with extra debug info, not just "(gdb)". How can I get this?)
Thanks!
An indexpath for a tableview cell needs to have both a row and a section. Try creating your index path using the factory method (defined in NSIndexPath UIKit Additions) like this instead:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[_form selectRowAtIndexPath:indexPath animated:YES scrollPosition:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With