这应该在我的任何给定表格行中显示一个占位符,除非存在该索引路径的图像。当我向下滚动时,前一个 indexPath 中的图像会加载默认值而不是释放。我知道以前有人帮助我解决了同样的问题,但这是在我意识到缓存图像的重要性之前。在我的 customCell 方法中,我将 UIImage 属性设置为 strong,并为 viewDidUnload 释放图像。
NSString *imagename = [_imageCache objectForKey:indexPath];
UIImage *preview = [_imageCache objectForKey:imagename];
if (preview)
{
[[cell myImageView] setImage:preview];
}
else
{
[[cell myImageView] setImage:[UIImage imageNamed:@"CellLogo.png"]];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
// __block UIImage *preview = nil;
UIImage *preview = [UIImage imageWithData:object.iG];
// }
if (preview)
{
dispatch_async(dispatch_get_main_queue(), ^{
// if (cell)
[[cell myImageView] setImage:preview];
});
[_imageCache setObject:preview forKey:imagename];
}
});
}