Reputation: 956
Is there a way to detect when a table view cell is going off of the screen? The opposite of tableView:willDisplayCell:forRowAtIndexPath:, like tableView:willHideCell:forRowAtIndexPath: would be great, but obviously it doesn't exist.
The reason I'd like to detect this is because whenever a new cell is shown, I'm downloading images to place in that cell, but if the user is simply scrolling by the cell and not viewing it, I would like to cancel the download of those images.
Upvotes: 1
Views: 884
Reputation: 1624
I believe it's 'didEndDisplaying'
https://developer.apple.com/reference/uikit/uicollectionviewdelegate/1618036-collectionview
Upvotes: 0
Reputation: 53551
In most cases, you won't need this, because the table view will usually always display the same number of cells, so a cell that goes offscreen will immediately be reused and in this case, the easiest approach would be to cancel the download after you dequeue the cell.
If you have a lot of different cell identifiers, this may not be the case though. One method I could think of would be to override willMoveToSuperview:
in your UITableViewCell
subclass and check the superview
parameter for nil (which means that it has been removed from the view hierarchy).
Upvotes: 1
Reputation: 5766
Just simply do that after you deque a cell from the tableview. As soon a cell pops of the screen it will be reused.
Upvotes: 1
Reputation: 862
Not exactly what you are asking for, but if you look at Apple's LazyTableImages sample, they delay starting the download of an image until scrolling ends:
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
Upvotes: 0