关于使用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放进你的工程里,加入头文件# ...
随机推荐
- awk纯干货
AWK的惊人表现: Awk设计的目的:简化一般文本处理的工作. 属于POSIX的一部分. AWK命令行: Awk的调用可以定义变量.提供程序并且指定输入文件: Awk [ -F fs ] [ -v ...
- RestTemplate进行表单请求,注意要使用MultiValueMap
在对接API的时候,有时候文档中会说,表单提交,这时候就需要用到 MultiValueMap来操作,下面给大家展示一个简单的demo. MultiValueMap<Object, Object& ...
- curl学习笔记(以php为例)
一.demo,抓取百度页码代码: $url = 'https://www.baidu.com/'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RE ...
- cocos2d中的anchorPoint属性详解
原文地址:http://www.tuicool.com/articles/ANVjMj 1> anchorPoint对position的影响 anchorPoint的作用就是相当于确定在子节点的 ...
- JAVA复制
复制 直接赋值 直接赋值.在 Java 中, A a1 = a2,我们需要理解的是这实际上复制的是引用,也就是说 a1 和 a2 指向的是同一个对象.因此,当 a1 变化的时候, a2 里面的成员变量 ...
- JS(异步与单线程)
JS(异步与单线程) 题目1.同步和异步的区别是什么,试举例(例子见知识点) 区别: 1.同步会阻塞代码执行,而异步不会 2.alert 是同步,setTimeout 是异步 题目2.关于 setTi ...
- HDU 3507 斜率优化 DP Print Article
在kuangbin巨巨博客上学的. #include <iostream> #include <cstdio> #include <cstring> #includ ...
- awk之NF的妙用
在awk中大家都知道NF的作用,它是一个awk的内建变量,代表是每行的字段数量.常用的几种方式我给大家慢慢到来.最多的就是在读取每个字段内容 for(i=1;i<=NF;i++) 这个运用 ...
- 【01】CSS规范
[01]CSS规范 []https://drafts.csswg.org/indexes/(下图) https://www.w3.org/TR/2011/REC-CSS2-20110607/ ...
- python基础-对象
1. 对象:一组数据和操作数据方法的集合 >>> class Person(object): ... def __init__(self,name): ... ...