Question

UITableView - what row was selected?

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.

 45  64405  45
1 Jan 1970

Solution

 109

If you haven't implemented a delegate (see nduplessis), UITableView also offers:

- (NSIndexPath *)indexPathForSelectedRow
2009-03-19

Solution

 36

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

2009-03-19