关于使用uitableview 中cell 来实现uiimageview的复用和图片的异步加载
apple sample lazytableimages
1,首先设置横向显示的uitableview
self.customTableview.transform = CGAffineTransformMakeRotation(M_PI/-2);
同时需要将cell也加以旋转否则其内部的图片是反的
cell.contentView.transform = CGAffineTransformMakeRotation(M_PI/2);
2,使用cell的imageview来实现图片的加载
cell.imageView.image = [UIImage imageNamed:@"timeline_image_loading@2x.png"];
这里需要给imageview首先添加占位的图片,否则的话当滚动时后面的cell会因为复用而加载前面已经显示的image
cell.imageView.frame = CGRectMake(0.0f, 0.0f, cell.frame.size.width, self.customTableview.frame.size.height);
3,判断下载图片
if (!self.record.appIcon)
{
{
//if the user does not dragging the scroll view then will start the download
if (self.customTableview.dragging == NO && self.customTableview.decelerating == NO)
{
NSString *startURL = self.record.photoURL;
//start the download if the image url is no tempty
if (startURL && (NSNull*)startURL != [NSNull null])
{
NSString *endURL = [NSURL URLWithString:startURL];
if (endURL)
{
[self startIconDownload:self.record withButtonWidth:self.customTableview.frame.size.width andButtonHeight:self.customTableview.frame.size.height forButtonIndex:indexPath.row andIndexPath:indexPath];
}
}
}
}
}else
{
cell.imageView.image = self.record.appIcon;
[cell.imageView setContentMode:UIViewContentModeScaleAspectFit]; //将裁剪好的图片以指定的大小显示出来
}
- (void)startIconDownload:(PhotosRecord *)appRecord withButtonWidth:(float)width andButtonHeight:(float)height forButtonIndex:(int)tag andIndexPath:(NSIndexPath *)indexPath{
PhotosDetailDownloader*iconDownloader = [self.imageDownloadsInProgress objectForKey:indexPath];;
if (iconDownloader == nil)
{
iconDownloader = [[PhotosDetailDownloader alloc] init];
iconDownloader.kids = appRecord;
[iconDownloader setAlbumPhotosDownloadCompletionHandler:^{
// Display the newly loaded image
if (appRecord.appIcon){
NSLog(@"downloaded index here is %d",indexPath.row);
UITableViewCell *cell = [self.customTableview cellForRowAtIndexPath:indexPath];
cell.imageView.image = appRecord.appIcon;
[cell.imageView setContentMode:UIViewContentModeScaleAspectFit];
[cell setNeedsLayout]; //这句很重要,否则下载成功后的首个cell和其后已经在屏幕中显示的cell的image无法显示出来。关于这点详见下面的回复
[self.imageDownloadsInProgress removeObjectForKey:indexPath];
}
// Remove the IconDownloader from the in progress list.
}
];
//防止图片重复下载?
if (iconDownloader) {
[self.imageDownloadsInProgress setObject:iconDownloader forKey:indexPath];
}
[iconDownloader startDownloadWithWidth:width andHeight:height];
[iconDownloader release];
}
}
|
I am experimenting in
and in
and it works if in If I use
or
in the completion block, it won't work, and if I use
in the completion block by making But is there an easy way to cause the image to show up? Setting a placeholder image works but what if we don't -- by what mechanism does placeholder cause the refresh of image? |
|||||||||
add comment |
|
When a I fixed the issue by calling
I found the completion block happens in the background so that necessitates performing my UI work on the main thread. Of course this solution won't account for cell reuse and so forth, but at least solves why the cell's image wouldn't appear :) Hope this helps! |
关于使用uitableview 中cell 来实现uiimageview的复用和图片的异步加载的更多相关文章
- Android中图片的异步加载
转: 1. 为什么要异步加载图片 下载图片比较费时,先显示文字部分,让加载图片的过程在后台,以提升用户体验 2. SoftReference的作用 栈内存—引用 堆内存—对象 Eg: Object ...
- IOS中UITableView异步加载图片的实现
本文转载至 http://blog.csdn.net/enuola/article/details/8639404 最近做一个项目,需要用到UITableView异步加载图片的例子,看到网上有一个E ...
- Swift - 异步加载各网站的favicon图标,并在单元格中显示
下面是一个简单的应用,表格视图的各个单元格自动异步加载各个网站的favicon图标,并显示出来. 主要是复习下如何自定义单元格,单元格中图片的异步加载,以及didSet的用法. 效果图如下: 操作步骤 ...
- UITableView中cell点击的绚丽动画效果
UITableView中cell点击的绚丽动画效果 本人视频教程系类 iOS中CALayer的使用 效果图: 源码: YouXianMingCell.h 与 YouXianMingCell.m / ...
- UITableView中cell里的UITextField不被弹出键盘挡住
UITableView中cell里的UITextField不被弹出键盘挡住 本人视频教程系类 iOS中CALayer的使用 效果如下: 源码: EditCell.h 与 EditCell.m // ...
- 如何获取UITableView中cell的frame值
如何获取UITableView中cell的frame值 这个可以用来处理UITableView弹出键盘的问题 本人视频教程系类 iOS中CALayer的使用 效果: 源码: // // ViewC ...
- 用适配器模式处理复杂的UITableView中cell的业务逻辑
用适配器模式处理复杂的UITableView中cell的业务逻辑 适配器是用来隔离数据源对cell布局影响而使用的,cell只接受适配器的数据,而不会与外部数据源进行交互. 源码: ModelCell ...
- ios UITableView 异步加载图片并防止错位
UITableView 重用 UITableViewCell 并异步加载图片时会出现图片错乱的情况 对错位原因不明白的同学请参考我的另外一篇随笔:http://www.cnblogs.com/lesl ...
- UIImageView异步加载网络图片
在iOS开发过程中,经常会遇到使用UIImageView展现来自网络的图片的情况,最简单的做法如下: 去下载https://github.com/rs/SDWebImage放进你的工程里,加入头文件# ...
随机推荐
- ECMAScript5 [].reduce()
ECMAScript 5 的2个归并数组的方法,reduce() reduceRight() 两个方法都会迭代数组的所有项,然后构建一个最终返回的值. 两个参数: 1.函数,一个在每一项上调用的函 ...
- [POJ] 2411 Mondriaan's Dream
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...
- python中函数定义之实参、形参
一般在函数的定义中,会有一类变量---形参,它是函数完成其工作的一项信息.实参往往是调用函数时传递给函数的信息.我们在调用函数时,将要让函数使用的信息放在括号内.例如定义一个函数def greet_u ...
- (42)zabbix使用IT services 了解服务器SLA整体情况
什么是IT Services 服务器或者某项服务.业务的可用率,不懂技术的上级领导会过问最近服务器可用率如何.所有api的状况怎么样? 通常一些技术人员会说负载怎么样,哪些cpu使用率怎么样,硬盘使用 ...
- Centos忘记密码解决方法
centos6.8忘记root密码解决方法 重启系统后出现GRUB界面在引导装载程序菜单上,用上下方向键选择你忘记密码的那个系统键入"e" 来进入编辑模式. 接下来你可以看到如下图 ...
- 快照、克隆,xshell优化,Linux历史
目录 一.虚拟拍照功能 二.虚拟机克隆功能 三.Xshell的优化 四.介绍Linux历史 一.虚拟拍照功能 1.拍摄快照 关机状态拍照 关机命令:shutdown -h now 或者 init 0 ...
- solr DIH 设置定时索引
1 web.xml中加入 web.xml所在目录 /opt/solr-7.7.1/server/solr-webapp/webapp/WEB-INF <listener> <list ...
- spring mvc3 配置<mvc:resources/> @Controller失效
因为配置了:<mvc:resources location=" " mapping="" /> ,@Controller失效访问404 这里还 ...
- C++枚举类型enum
为啥需要枚举类型 编程语言中的所有特性都是为了满足某种需求,达到某个目的还出现.不会莫名其妙的出现在那. 枚举可以用来保存一组属性的值.enum的全称是enumeration意思是列举 看着这句话可能 ...
- 【Luogu】P1393动态逆序对(树套树)
题目链接 树套树. 每次删掉x的时候会减去1到x-1里比x位置的数大的数和它构成的逆序对,以及x+1到n里比x位置的数小的数和它构成的逆序对. 顺带一提我发现平衡树insert的时候不是要splay一 ...