我有这种方法,UIImageView
当单击单元格时,它会下载全尺寸图像。
- (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!"];
在未缓存时调用?