views:

27

answers:

2

Hi,

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.

+1  A: 

In didSelectRowAtIndexPath, set an interface declared NSIndexPath as the indexpath returned. Then you can scroll to that variable. If you need help, comment and I can give some sample code.

Kolin Krewinkel
Yes please post some sample code
imMobile
Sample code: http://pastie.org/1254081
Kolin Krewinkel
Alternatively, you can use Chris's method for quicker use. The above method offers more control and can be modified by your (example) detail view controller.
Kolin Krewinkel
A: 
NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];
Chris Gummer