iphone table 实现动态加载图片
2011-06-21 19:15
561 查看
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; }
相关文章推荐
- iphone table 实现动态加载图片
- iphone table 实现动态加载图片
- iPhone学习之路 TableView实现动态加载图片
- iPhone table 实现动态加载图片的教程-TableView中图片的延时加载
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程
- IOS之tableview 实现动态加载图片
- jQuery页面滚动图片等元素动态加载实现
- jQuery实现动态加载大尺寸图片
- iPhone UITableView异步加载图片 (动态加载图片)
- jQuery页面滚动图片等元素动态加载实现
- 使用sdWebImage实现对tableView的cell加载图片淡入淡出效果
- iPhone开发【十三】动画效果之最简单的动画——动态加载图片
- iphone(UITableViewCell)动态加载图片
- iphone中使用NSoperation实现图片异步加载
- tableview实现cell有间隔,cell加载背景图片和选中图片
- [转]jQuery页面滚动图片等元素动态加载实现
- jQuery页面滚动图片等元素动态加载实现