UITableView NSThread 实现动态加载图片
来源:互联网 发布:hbase数据库设计例子 编辑:程序博客网 时间:2024/05/22 12:53
iPhone在加载列表时,如果每个等待把所有列表中的数据都加载完在显示相关内容,如果列表中有一些比较大的图片,加载的时间比较长,那么给用户的效果就很差了,下面详细是一种实现动态加载图片的办法:
<span style="font-size:10px;">- (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; }</span>
0 0
- UITableView NSThread 实现动态加载图片
- iPhone UITableView异步加载图片 (动态加载图片)
- UITableView 实现异步加载图片之改进
- Flex 实现动态加载图片
- Promise实现图片动态加载
- UITableView 异步加载图片
- UITableView异步加载图片
- UITableView异步加载图片
- UITableView异步加载图片
- UITableView 异步加载图片
- UITableView缓存加载图片
- IOS中UITableView异步加载图片的实现
- IOS中UITableView异步加载图片的实现
- iPhone UITableView异步加载图片
- iPhone UITableView异步加载图片
- ios uitableview加载图片优化
- iphone table 实现动态加载图片
- flex中如何实现动态加载图片
- UVA 662 Fast Food(DP)
- U盘和电脑USB都是好的,可是插上u盘没任何反应!
- 黑马程序员 正则表达式
- ios视图层次结构
- hust校赛d题 PHP is the best language int the world(二分图着色+递推)
- UITableView NSThread 实现动态加载图片
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 9: ordinal not in range(128)
- 数据结构之常见的排序算法2
- Binary Tree Postorder Traversal - LeetCode 145
- python 服务器和客户端简单原型
- 【转载】【译文】Lisp魔咒:对Lisp的非技术性吐槽
- Win32调试API原理
- 文件存储的实现-login登录案例2-sdcard
- 程序源代码复制到word格式不变