【问题标题】:AFNetworking check if image is cachedAFNetworking 检查图像是否被缓存
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 当我打开同一个单元格时,imageView 已经加载了下载的图像,这是为什么呢?
    • 当我关闭并打开应用程序并打开单元格时,图像没有下载,它在那里
    猜你喜欢
    • 1970-01-01
    • 2010-11-14
    • 2011-10-29
    • 2016-01-05
    • 1970-01-01
    • 2015-12-14
    • 2012-11-18
    • 2017-04-03
    • 1970-01-01
    相关资源
    最近更新 更多