TableView 动态加载图片
来源:互联网 发布:数字三角形问题 算法 编辑:程序博客网 时间:2024/05/17 08:02
iPhone在加载列表时,如果每个等待把所有列表中的数据都加载完在显示相关内容,如果列表中有一些比较大的图片,加载的时间比较长,那么给用户的效果就很差了,下面详细是一种实现动态加载图片的办法:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"tag"];
if (cell==nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"tag"] autorelease];
}
//表格设计
NSDictionary* one = [array objectAtIndex:indexPath.row];
cell.textLabel.text = [one objectForKey:@"title"];
cell.detailTextLabel.text = [one objectForKey:@"content"];
[NSThread detachNewThreadSelector:@selector(updateImageForCellAtIndexPath:) toTarget:self withObject:indexPath];
return cell;
}- (void)updateImageForCellAtIndexPath:(NSIndexPath *)indexPath
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImage *image = [self getImageForCellAtIndexPath:indexPath];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];
[image release];
[pool release];
}
-(UIImage *)getImageForCellAtIndexPath:(NSIndexPath *)indexPath
{
id path = [[array objectAtIndex:indexPath.row] objectForKey:@"image"];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data cache:NO];
return image;
}源码地址
- TableView 动态加载图片
- IOS之tableview 实现动态加载图片
- iPhone学习之路 TableView实现动态加载图片
- tableview 图片异步加载
- tableview加载图片优化
- tableview加载图片优化
- iPhone table 实现动态加载图片的教程-TableView中图片的延时加载
- TableView中图片延时加载
- TableView中图片加载优化
- 动态设置TableView加载完毕后TableView的高度
- 关于TableView中图片的延时加载
- TableView中图片的延时加载
- iPhone TableView中图片的延时加载
- 关于TableView中图片的延时加载
- 关于TableView中图片的延时加载
- iPhone TableView中图片的延时加载
- iPhone TableView中图片的延时加载
- 关于TableView中图片的延时加载
- 插入记录时单引号的处理
- c#怎么样让double保留两位小数
- 严苛模式(StrictMode)
- [LeetCode]Reorder List
- Perl传递结构体指针
- TableView 动态加载图片
- 三星平臺添加模擬i2c 控制器
- .Net 微信公众帐号实现发送消息
- linux下文件删除不了
- E-R模型转化成关系模型
- [LeetCode]Linked List Cycle II
- 黑马程序员_命名空间
- ZOJ 3160 区间DP
- bootstrap中的button groups