Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Selected index of UITableView

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.

like image 673
iOSDev Avatar asked Oct 27 '10 07:10

iOSDev


2 Answers

NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow]; 
like image 200
Chris Gummer Avatar answered Oct 17 '22 13:10

Chris Gummer


Get current selected row. May be helpful if you have only one section.

- (NSUInteger)currentSellectedRowIndex {     NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];     if (selectedIndexPath) {         return selectedIndexPath.row;     }     else {         return NSNotFound;     } } 
like image 28
Nuzhdin Vladimir Avatar answered Oct 17 '22 14:10

Nuzhdin Vladimir