Reputation: 53540
I have a question - how can I get a number of row selected in a table? I am assigning it manually to a variable. The problem is that if a row was deselected, my variable still keeps the old value.
What can I do about it? Is there a method in UITableView that returns a number of a currently selected row?
Thank you in advance, Ilya.
Upvotes: 45
Views: 64409
Reputation: 97902
If you haven't implemented a delegate (see nduplessis), UITableView also offers:
- (NSIndexPath *)indexPathForSelectedRow
Upvotes: 109
Reputation: 12436
The UITableViewDelegate will call
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
when a row is selected. From this you can easily determine the row by using indexPath.section and indexPath.row
Upvotes: 36