Search code examples
iosobjective-cuitableviewnsindexpath

Exception when manually calling didSelectRowAtIndexPath


I am attempting to manually call didSelectRowAtIndexPath on a UITableview. When doing so I get the following exception:

'Invalid index path for use with UITableView.  Index paths passed to table view must contain exactly two indices specifying the section and row.

Here is the code causing the exception:

-(void)refreshLayerAtIndexPath:(NSUInteger)index {
    NSIndexPath* indexPath = [[NSIndexPath alloc] initWithIndex:index];
    [self tableView:_tableViewLayers didSelectRowAtIndexPath:indexPath];
}

I see nowhere to explicitly set the section.

Any suggestions? Thanks!


Solution

  • With UITableView you also need to specify the section of NSIndexPath

    NSIndexPath* indexPath = [NSIndexPath indexPathForRow:row inSection:section];