Get Selected index of UITableView

iOSDev picture iOSDev · Oct 27, 2010 · Viewed 83.4k times · Source

I want to have selected index for UITableView. I have written following code:

NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];
[tableView scrollToRowAtIndexPath:index 
                 atScrollPosition:UITableViewScrollPositionTop 
                         animated:YES];

This always work for 1st item. I want to have selected index in indexPathForRow.

Please help. Thanks.

Answer

Chris Gummer picture Chris Gummer · Oct 27, 2010
NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];