Validation error for UITableView selectRowAtIndexPath

I feel this is a problem that needs special attention ... my google fu is pretty good, but I couldn’t get anything useful.

This is the simplest thing, and yet I cannot understand what the problem is with it.

I have a UITableView. This is the subclause that my VC calls _form. I use it for styling, not for displaying data. It has 2 cells.

In a specific event, I'm trying to select another cell using selectRowAtIndexPath: animated: scrollPosition.

When I do this, it is 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 name of the button changes, And the table prints that the selected row is 0 or 1, but when you try to select the desired cell, it splits:

 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 guess is that this means that something is wrong with setting up my table, but I'm not sure what. Selecting cells in a table usually (click) works as indicated by the expected response in my tableView: didSelectRowAtIndexPath. Everything else works fine with the way I configured it other than this.

(Also, I, other people, respond with more debugging information, not just “(gdb).” How can I get this?)

Thanks!

+6
source share
1 answer

The index path for the tableview cell must have both a row and a section. Try creating your index path using the factory method (defined in NSIndexPath UIKit Additions ) as follows:

 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [_form selectRowAtIndexPath:indexPath animated:YES scrollPosition:YES]; 
+18
source

Source: https://habr.com/ru/post/910393/


All Articles