UITableView Cell IndexPath

Leonardo Marques picture Leonardo Marques · Mar 30, 2010 · Viewed 30.6k times · Source

Can anyone tell me how can I get a cell IndexPath? I was saving the IndexPath in the tableView: cellForRowAtIndexPath: method but this only loads when the cell is viewed and I need to know its index path on the viewDidLoad method. this resulted in a null value because as I said it only loads its value after the cell was viewed once.

Thank you.

EDIT

The intention is being able to jump to a specific cell that has its specific number but its not linear with the sections and rows count.

Answer

progrmr picture progrmr · Apr 1, 2010

Use the method indexPathForCell: on the tableView, given a pointer to a UITableViewCell it returns its indexPath.

You can put the scrollToRowAtIndexPath:atScrollPosition:animated: in the viewWillAppear method if it is not set up yet in viewDidLoad. This is a better place anyway if the view can appear more than once after being loaded, such as when a modal view controller it invokes resigns.