1

我有这种方法,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!"];在未缓存时调用?

4

1 回答 1

1

AFImageRequestOperation 不缓存图像。我认为您将 AFNetworking 的类别“UIImageView+AFNetworking”与“AFImageRequestOperation”混淆了。类别会缓存图像,AFImageRequestOperation 不会。

于 2012-12-11T16:27:24.550 回答