indexPathForSelectedRow returning nil

A possible cause is that you've written something in one of the UITableViewDelegate methods -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}

It's a common practice to deselect the row which has just been selected.

Update:

In Swift 4.2, xcode 10:

Just comment the line

tableView.deselectRow(at: indexPath, animated: true)

in the function

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

Something that may help others - if you call reloadData() on your table view, it nilifies the indexPathForSelectedRow.


Be sure, you are not calling deselectRowAtIndexPath method before getting index path of selected Row.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; //add this line after setting indexPath
}