我正在创建一个自定义UITableViewCell
以包含UIImageView
和一些相关文本。我从互联网获取图像,并在图像加载时显示临时文件UIImage
。UITableViewCell中的UIImageView没有得到更新
我正在使用单独的线程获取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
。