Reputation: 16051
So this may be sort of difficult to explain, but I'll do my best. This problem might take a few steps to solve too.
This code appears in a tableviewcell, so it's ran every time the cell comes on screen:
[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.
}
The problem is, when it comes back round to removing all the objects, it seems to remove the actual UIImages from record, because an NSLog on the thumbnailsCache shows the entry to be empty. It's the removeAllObjects line that does it, but if it's kept then it just keeps adding more media to the cell.
Upvotes: 0
Views: 92
Reputation: 558
Try assign simple copy, like i.e.:
[self.cellThumbnailCache setObject:[NSSet setWithSet:cell.cellContent.thumbnails] ....
Upvotes: 2