iPhone table 实现动态加载图片的教程
2010-10-26 14:25
731 查看
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;
}
源代码:http://easymorse-iphone.googlecode.com/svn/trunk/WelcomePavilion/
转自 http://wangjun.easymorse.com/?p=908
相关文章推荐
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程-TableView中图片的延时加载
- iPhone table 实现动态加载图片的教程
- iphone table 实现动态加载图片
- iphone table 实现动态加载图片
- iphone table 实现动态加载图片
- iPhone学习之路 TableView实现动态加载图片
- IOS之tableview 实现动态加载图片
- iPhone table 实现动态加载图片的教程
- iPhone TableView中图片的延时加载
- 使用CSS3实现动态加载gif图片的效果
- Android图片加载神器之Fresco-圆形圆角二合一教程[Java代码实现圆形圆角效果]
- Android实战简易教程<四十九>(两种方式实现网络图片异步加载)
- 从JSON取数据实现图片瀑布流布局的数据动态加载
- iphone动态加载图片
- [unity基础教程]关于Unity3D中Resources动态加载NGUI图片的方法!
- [转]jQuery页面滚动图片等元素动态加载实现
- 动态加载图片,并且实现小图呈现大图
- iPhone利用线程实现数据的加载并在Table中展示