我正在使用 AFNetworking 为单元格占位符加载我的图像。这是我的代码示例。 ( token 来自 here)
NSURL *url = [NSURL URLWithString:daysWeather.weatherIconURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIImage *placeholderImage = [UIImage imageNamed:@"placeholder"];
__weak UITableViewCell *weakCell = cell;
[cell.imageView setImageWithURLRequest:request
placeholderImage:placeholderImage
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
NSLog(@"Load placeholder img");
weakCell.imageView.image = image;
[weakCell setNeedsLayout];
} failure:nil];
return cell;
现在我有一个问题。此图像是否每次都加载,当它变得可见时?如您所见,我在成功 block 中添加了 NSLog(@"Load placeholder img");
。我看到,这段代码每次都会调用,当单元格变得可见时(在它可见之后,消失并再次变得可见)
最佳答案
Yes success block 每次都被调用。但是 AFNetworking 只会下载一次图像并将其保存在缓存中。一旦您再次请求相同的 URL 或图像,它将直接从缓存中加载图像(如果可用)。
此外,如果您不想在 block 中执行任何特定操作,则只需使用 setImageWithURL:placeholderImage。
关于ios - UITableViewCell 占位符图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35359036/