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.
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section. For example, the first row in a table would have section 0, row 0, whereas the eighth row in the fourth section would have section 3, row 7.
First, design your table cell on Storyboard whatever you want. Now, make a subclass of UITableViewCell and assign this class to your prototype custom cell which you have designed on Storyboard. Also, don't forget to set "reuse identifier in Storyboard table cell.
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.
A UITableViewCell
doesn't have an NSIndexPath
property. The UITableViewDataSource
delegate defines methods that ask for a cell for a given NSIndexPath
, but that doesn't mean the cell has any enduring relationship to an NSIndexPath
property.
Maybe it would help if you explained more of what you wanted this property for? What do you want to do with the cell's location in viewDidLoad
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With