关于使用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放进你的工程里,加入头文件# ...
随机推荐
- 自写小函数处理 javascript 0.3*0.2 浮点类型相乘问题
const reg = /^([-+]?)([0-9]+)\.([0-9]*)$/; // 判断是不是浮点数 const isFloat = function(number){ return reg. ...
- luogu P2574 XOR的艺术 (线段树)
luogu P2574 XOR的艺术 (线段树) 算是比较简单的线段树. 当区间修改时.\(1 xor 1 = 0,0 xor 1 = 1\)所以就是区间元素个数减去以前的\(1\)的个数就是现在\( ...
- 五分钟入门 Dingo API
基于 https://laravel-china.org/doc... 文档更简洁的描述Dingo,直戳重点,注重实践 Django-Book 概述 Dingo API帮助您轻松快速地构建自己的API ...
- A Fast and Easy to Use AES Library
http://www.codeproject.com/Articles/57478/A-Fast-and-Easy-to-Use-AES-Library Introduction EfAesLib i ...
- Python-求解两个字符串的最长公共子序列
一.问题描述 给定两个字符串,求解这两个字符串的最长公共子序列(Longest Common Sequence).比如字符串1:BDCABA:字符串2:ABCBDAB.则这两个字符串的最长公共子序列长 ...
- django 12天(跨域,文件上传,下载,cookie,session)
django 12天(跨域,文件上传,下载) 跨域 什么是跨域 1.协议不同 2.端口不同 3.主机不同 如何解决跨域 1.安装django-cors-headers模块 2.在settings.py ...
- int (*a)[10] 和 int *a[10] 的区别
int *a[10] :指针数组.数组a里存放的是10个int型指针 int (*a)[10] :数组指针.a是指针,指向一个数组.此数组有10个int型元素 int *a[10] 先找到声明符a,然 ...
- Codeforces Round #204 (Div. 2)
D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- tomcat在centos6+上的自启动脚本
#!/bin/bash # # tomcat startup script for the Tomcat server # # chkconfig: 345 80 20 # description: ...
- [BZOJ3611] [Heoi2014]大工程(DP + 虚树)
传送门 $dp[i][0]$表示节点i到子树中的所有点的距离之和 $dp[i][1]$表示节点i到子树中最近距离的点的距离 $dp[i][2]$表示节点i到子树中最远距离的点的距离 建好虚树后dp即可 ...