【发布时间】:2012-11-29 05:43:33
【问题描述】:
我有这个方法,当点击单元格时,它会下载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!"];?
【问题讨论】:
标签: iphone ios ipad caching afnetworking