【发布时间】:2009-02-13 23:01:48
【问题描述】:
我正在创建一个自定义 UITableViewCell 以包含 UIImageView 和一些相关文本。我从 Internet 获取图像,当图像加载时,我会显示一个临时的 UIImage。
我正在使用单独的线程来获取UIImage。一旦下载了UIImage,我将在主线程上触发一个方法来设置UIImageView 中的图像(使用标签获取UIImageView 的实例)
但无论我做什么,图像都不会改变。单元格仍显示较旧的图像(对应于不同的行 - 由于单元格的重复使用)并且不会反映新图像。日志语句显示正在调用设置图像的方法。
我什至尝试将图像更改为willDisplayCell:forRowAtIndexPath: 中的静态图像
但即便如此,图像也不会改变。
编辑
在更改UIImage 后,我尝试在UITableView 上调用reloadData,但UIImage 仍然没有更改。
这是相关的代码
cellForRowAtIndexPath
image = [imagesArray valueForKey:[NSString stringWithFormat:@"%i",indexPath.row]];
if(image == nil){
//display temporary images. When scrolling stops, detach new thread to get images for rows visible
NSString *pth = [[NSBundle mainBundle] pathForResource:@"folder" ofType:@"png"];
image = [UIImage imageWithContentsOfFile:pth];
[imgView setImage:image];
}
else{
[imgView setImage:image];
}
图片下载后在主线程调用的方法
-(void)setImageInArray:(NSIndexPath *)indPath{
[filesTable reloadData];
}
在线程中,我将UIImage 对象添加到imagesArray。所以下次在reloadData上调用cellForRowAtIndex方法时,应该会显示新的UIImage。
【问题讨论】:
标签: iphone cocoa-touch uitableview