1

我正在创建一个自定义UITableViewCell以包含一个UIImageView和一些相关文本。我从 Internet 获取图像,当图像加载时,我会显示一个临时的UIImage.

我正在使用单独的线程来获取UIImage. 一旦UIImage下载了一个,我就会在主线程上触发一个方法来设置图像UIImageView(获取UIImageView使用标签的实例)

但无论我做什么,图像都不会改变。单元格仍显示较旧的图像(对应于不同的行 - 由于单元格的重复使用)并且不会反映新图像。日志语句显示正在调用设置图像的方法。

我什至尝试将图像更改为静态图像,willDisplayCell:forRowAtIndexPath: 但即使那样图像也不会改变。

编辑
我尝试在更改后调用reloadDataUITableViewUIImage仍然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调用该方法时reloadDataUIImage应该显示新的。

4

1 回答 1

5

UITableView 的单元格是缓存的,所以在渲染完单元格后修改它不会有任何效果。reloadData更新 UIImageView 后,尝试向表格发送消息。

于 2009-02-13T23:11:59.937 回答