los*_*sit 1 iphone cocoa-touch uitableview
我正在创建一个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];
}
Run Code Online (Sandbox Code Playgroud)
下载图像后在主线程上调用的方法
-(void)setImageInArray:(NSIndexPath *)indPath{
[filesTable reloadData];
}
Run Code Online (Sandbox Code Playgroud)
在线程中,我将UIImage对象添加到imagesArray.因此,当下次cellForRowAtIndex调用该方法时reloadData,UIImage应显示新方法.
| 归档时间: |
|
| 查看次数: |
2402 次 |
| 最近记录: |