Given the indexPath
of a UITableViewCell, I want to know whether the cell currently exists.
I know how to check if it's on the screen (use tableView.indexPathsForVisibleRows
). However, I also want to know if it's off the screen but already created (assuming the user has scrolled but it hasn't quite entered the screen are yet).
How do I do this?
You can do
[self.tableView cellForRowAtIndexPath:indexPath];
(not to be confused with the data source method [self tableView:cellForRowAtIndexPath:]
) and if a cell for that index path exists, it will be returned. Otherwise, you'll get nil
.
You definitely don't want your background update process to hold a direct reference the cell because, as you said, it may have scrolled off screen and been recycled by the time the fetch completes. Instead, hold a reference to the index path or some piece of data that can be used to look up the index path and then use that index path with the above method to retrieve the cell.
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