0

所以这可能有点难以解释,但我会尽力而为。这个问题也可能需要几个步骤来解决。

此代码出现在 tableviewcell 中,因此每次单元格出现在屏幕上时都会运行它:

[cell.cellContent.thumbnails removeAllObjects];

if ([self.cellThumbnailCache objectForKey:[NSNumber numberWithInt:indexPath.row]]) {
    cell.cellContent.thumbnails = [self.cellThumbnailCache objectForKey:[NSNumber numberWithInt:indexPath.row]];
    [cell.cellContent setNeedsDisplay];
}
else {

    //First it removes all the existing UIImages from the cell.cellContent.thumbnails mutable array.
    int i = 0;

    while (i < numberOfThumbnailsToDraw) {
        Media *media = [entryNewMoc.media objectAtIndex:i];
        UIImage *image = [media getThumbnail];

        [newMoc save:nil];

        [cell.cellContent.thumbnails addObject:image];
        i++;
    }

    //Then it goes through getting UIImages and adding them to the array.
    [self.cellThumbnailCache setObject:cell.cellContent.thumbnails forKey:[NSNumber numberWithInt:indexPath.row]];
    [cell.cellContent setNeedsDisplay];

    //Then it all gets drawn in setNeedsDisplay.
}        

问题是,当它返回删除所有对象时,它似乎从记录中删除了实际的 UIImages,因为 thumbnailsCache 上的 NSLog 显示该条目为空。执行此操作的是 removeAllObjects 行,但如果保留它,它只会继续向单元格添加更多媒体。

4

1 回答 1

2

尝试分配简单的副本,例如:

[self.cellThumbnailCache setObject:[NSSet setWithSet:cell.cellContent.thumbnails] ....
于 2012-06-12T02:16:54.073 回答