1
我有这种方法,它可以在单击单元格时下载UIImageView
的全尺寸图像。AFNetworking检查图像是否缓存
- (void)configureView
{
NSURLRequest *URLRequest = [[NSURLRequest alloc] initWithURL:self.imageURL];
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:URLRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
[SVProgressHUD showSuccessWithStatus:@"Done!"];
[self.imageView setImage:responseObject];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
float percentage = (totalBytesRead/(totalBytesExpectedToRead * 1.0f) * 100);
NSLog(@"Percentage: %f", percentage);
if (percentage != 100.0)
{
[SVProgressHUD showWithStatus:[NSString stringWithFormat:@"Downloading... %0.0f%%", percentage]];
}
}];
[operation start];
}
因此,当下载完成时,调用[SVProgressHUD showSuccessWithStatus:@"Done!"];
。 但是当您回到tableViewController
并单击相同的单元格时,即使图像被缓存,[SVProgressHUD showSuccessWithStatus:@"Done!"];
也会再次被调用。 如何检查图像是否缓存,只在不是时调用[SVProgressHUD showSuccessWithStatus:@"Done!"];
?
当我打开同一个单元格时,imageView已经加载了下载的图片,为什么? – 1337code
当我关闭并打开应用程序并打开单元格时,图像未下载,它在那里 – 1337code