LazyTableImages
官方demo http://download.csdn.net/detail/jlyidianyuan/5726749
在tableView:cellForRowAtIndexPath方法中
// Only load cached images; defer new downloads until scrolling ends
//图片是否存在
if (!appRecord.appIcon)
{
//tableView是否在拖拽或减速
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
{
//开个线程或使用GCD异步下载图片 下载图片后可以将图片存在沙盒 此处不详情写出
[self startIconDownload:appRecord forIndexPath:indexPath];
}
// if a download is deferred or in progress, return a placeholder image
//放张默认的图片
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
}
else
{
cell.imageView.image = appRecord.appIcon;
}
//实现UIScrollViewDelegate
#pragma mark -
#pragma mark Deferred image loading (UIScrollViewDelegate)
// 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];
}
- (void)loadImagesForOnscreenRows
{
if ([self.entries count] > 0)
{
NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in visiblePaths)
{
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
if (!appRecord.appIcon) // avoid the app icon download if the app already has an icon
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
}
}
}

浙公网安备 33010602011771号