I use the following code to trigger image downloads in visible cells/paths:
- (void)loadImagesForOnScreenrows {
NSArray *visiblePaths = [tableView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in visiblePaths) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if([cell viewWithTag:kTagImageView] != nil) {
(ImageViewCached *)[[cell viewWithTag:kTagImageView] triggerDownload];
}
}
}
// Load images for all onscreen rows when scrolling is finished
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
[self loadImagesForOnscreenRows];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self loadImagesForOnscreenRows];
}
However, apparently the indexPaths returned do not reflect the actual onscreen rows.
Especially if I scroll fast, the rows returned will be ones that are already off screen.
Can anyone think of a good (probably obvious) reason why that would be the case?
Is -loadImagesForOnscreenRows being called anywhere else?
It looks like you started from the LazyTableImages sample code. I could only get that sample project to invoke -loadImagesForOnscreenRows when scrolling ended (or at the end of a drag).
Scrolling fast was irrelevant in that project, since the visible rows aren’t asked for until scrolling stops.
I only tried the LazyTableImages code on the simulator, not a device. YMMV.