views:

3026

answers:

2

Hi,

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.

+3  A: 

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

nduplessis
+4  A: 

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

- (NSIndexPath *)indexPathForSelectedRow
Jarret Hardie
Thank you, Jarret, that is what I needed. Now everything is working perfectly.
Ilya