2009-02-13 66 views
1

我正在創建一個自定義UITableViewCell以包含UIImageView和一些相關文本。我從互聯網獲取圖像,並在圖像加載時顯示臨時文件UIImageUITableViewCell中的UIImageView沒有得到更新

我正在使用單獨的線程獲取UIImage。一旦UIImage下載,我在主線程燒製方法設置在UIImageView的圖像(獲得的UIImageView使用標籤實例)

但無論我做什麼,圖像不會改變。細胞仍然顯示較舊的圖像(對應於不同的行 - 由於重新使用細胞)並且不反映新圖像。日誌語句顯示正在調用設置圖像的方法。

我甚至試圖將圖像更改爲靜態圖像willDisplayCell:forRowAtIndexPath: 但即使如此,圖像不會改變。

編輯
我試圖改變UIImage後呼籲UITableViewreloadData,但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

回答

5

UITableView的單元格被緩存,所以修改單元格已被渲染後將不起作用。在更新UIImageView之後,嘗試發送表消息。