iOS延时加载图片
来源:互联网 发布:黑子的篮球 知乎 编辑:程序博客网 时间:2024/05/29 16:18
重网上下载图片是很慢的,为了不影响体验,选择延时加载图片是很好的办法。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"myCell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// 设置cell一些数据
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
cell.textLabel.text = appRecord.appName;
cell.detailTextLabel.text = appRecord.artist;
// 如果不存在图片
if (!appRecord.appIcon)
{
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)//不在拖动中和减速时,开始下载图片
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
//设置图片为空白图片(等待下载)
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
}
//如果有图片
else
{
cell.imageView.image = appRecord.appIcon;
}
return cell;
}
- (void)startIconDownload:(AppRecord *)appRecord forIndexPath:(NSIndexPath *)indexPath
{
IconDownloader *iconDownloader = [imageDownloadsInProgressobjectForKey:indexPath];
if (iconDownloader == nil) //已经在下载中的不用重复下载了,没有在下载中就往下走
{
iconDownloader = [[IconDownloader alloc] init];
iconDownloader.appRecord = appRecord;
iconDownloader.indexPathInTableView = indexPath;
iconDownloader.delegate = self;
[imageDownloadsInProgress setObject:iconDownloader forKey:indexPath];
[iconDownloader startDownload];
[iconDownloader release];
}
}
IconDownloader 是一个下载图片封装类
- (void)appImageDidLoad:(NSIndexPath *)indexPath
{
IconDownloader *iconDownloader = [imageDownloadsInProgressobjectForKey:indexPath];
if (iconDownloader != nil)
{
UITableViewCell *cell = [self.tableViewcellForRowAtIndexPath:iconDownloader.indexPathInTableView];
cell.imageView.image = iconDownloader.appRecord.appIcon;
}
}
- (void)startDownload
{
self.activeDownload = [NSMutableData data];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:appRecord.imageURLString]] delegate:self];
self.imageConnection = conn;
[conn release];
}
- iOS延时加载图片
- 图片延时加载
- 网页图片延时加载
- 图片延时加载
- Jquery 延时加载图片
- 网站图片延时加载
- 图片延时加载
- iOS开发中如何解决TableView中图片延时加载
- [iOS] 延时加载TableView中Cell中的图片
- iOS开发中如何解决TableView中图片延时加载
- IOS 延时加载TableView中Cell中的图片
- iOS开发中如何解决TableView中图片延时加载
- ios 延时加载
- js 延时加载 内容 图片
- Android Textview 延时加载图片
- jquery实现图片延时加载
- jquery lazyload 图片延时加载
- js控制图片延时加载
- OpenCV学习C++接口:图像遍历+像素压缩
- 老码农教你学英语
- HDU 4488Faulhaber’s Triangle(模拟 题目有公式)
- 我拒绝接受的几个最佳编程实践方法
- In the company, how to write an E-mail(在公司里,如何写好一封电子邮件)
- iOS延时加载图片
- MyEclipse断点调试文章-tomcat
- 老码农教你学英语(附带:补充一些英语学习素材)
- dreamer
- ListActivity
- 第一章 创建自己的GNU/Liunx系统——LFS
- android 自定义进度条
- WebBrowser页面与WinForm交互技巧
- String、StringBuffer与StringBuilder之间区别