因此,这可能很难解释,但我会尽力而为。这个问题也可能需要一些步骤来解决。
此代码显示在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.
}
问题是,当它回到删除所有对象的回合时,似乎从记录中删除了实际的UIImage,因为thumbnailsCache上的NSLog显示该条目为空。它是removeAllObjects行,但是如果保留,那么它将继续向该单元中添加更多媒体。
最佳答案
尝试分配简单的副本,例如:
[self.cellThumbnailCache setObject:[NSSet setWithSet:cell.cellContent.thumbnails] ....