Search code examples
didselectrowatindexpathuitableview

UITableViewController indexPathForSelectedRow returns incorrect value


I'm not sure what is going on but I have a list that has 3 items and I am selecting row 1.

I am using a viewcontroller that is a UITableViewController and that has a property tableView where I am accessing the indexPathForSelectedRow during the didSelectRowAtIndexPath.

For some reason this value is incorrect sometimes...

What could cause this?

The UITableView * param on didSelectRowAtIndexPath is also called tableView.


Solution

  • If your table has more than one section that can confuse things (it's caught me before). indexpath.row will return the row number in the section of the table, not the row number of the overall table. If that's not what you're expecting it'll appear wrong.