[英]AFNetworking check if image is cached
我有這種方法,當單擊單元格時,它將為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!"];
什么時候不?
AFImageRequestOperation不緩存圖像。 我認為您將AFNetworking的類別“ UIImageView + AFNetworking”與“ AFImageRequestOperation”混淆了。 類別不緩存圖像,AFImageRequestOperation不緩存圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.