Get Selected index of UITableView

Viewed 85246

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.

5 Answers

Swift 4.2

let selectedIndexPath = tableView.indexPathForSelectedRow

which is an optional return value.

Related