我正在创建自定义UITableViewCell
以包含UIImageView
和一些相关文字。我从互联网上获取图像,当图像加载时,我显示一个临时的UIImage
。
我使用单独的线程来获取UIImage
。下载UIImage
后,我在主线程上触发一个方法,在UIImageView
中设置图像(使用标记获取UIImageView
的实例)
但无论我做什么,图像都不会改变。单元格仍然显示较旧的图像(对应于不同的行 - 由于重复使用单元格)并且不反映新图像。日志语句显示正在调用设置图像的方法。
我甚至尝试将图片更改为willDisplayCell:forRowAtIndexPath:
中的静态图片
但即使这样,图像也不会改变。
修改的
我在更改reloadData
后尝试在UITableView
上调用UIImage
,但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
。因此,下次在cellForRowAtIndex
上调用reloadData
方法时,应显示新的UIImage
。
答案 0 :(得分:5)
UITableView的单元格被缓存,因此在渲染单元格之后修改单元格将不起作用。在更新UIImageView后,尝试向表发送reloadData
消息。