【问题标题】:SDImageCache unable to retrieve the saved images in CacheSDImageCache 无法检索缓存中保存的图像
【发布时间】:2017-10-03 22:24:29
【问题描述】:

我正在使用 SDWebImage 使用一个键将图像存储在缓存和磁盘内存中,但是在使用该键查询时我没有得到图像,代码是

 SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"ImageCacheFolder"];
[imageCache queryCacheOperationForKey:[entryidarray objectAtIndex:indexpath.row] done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
    if (image) {
        NSLog(@"image get from cache");
        [imageview setImage:image];
    } else {
        [imageview sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"PlaceholderImage-Day"] options:SDWebImageProgressiveDownload];
    } 
}];

NSURL *url = [NSURL URLWithString:imgStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];

if (img) {
    NSLog(@"the image is not nil");
    [[SDImageCache sharedImageCache] storeImage:img forKey:[entryidarray objectAtIndex:indexpath.row] toDisk:YES completion:nil];
}else {
    NSLog(@"the image is nil");
}

【问题讨论】:

  • 默认SDImageCache使用了缓存策略,那么为什么需要额外的缓存
  • 有一个功能,我需要使用密钥获取图像,这就是我尝试喜欢的原因。
  • 好吧,那你为什么使用两个线程
  • 由于它没有工作,现在我只使用一个线程并且它工作正常。感谢您通知我该错误兄弟:-)

标签: ios objective-c caching sdwebimage


【解决方案1】:

试试这个 .

if (img) {
    NSLog(@"the image is not nil");
    [imageCache storeImage:img forKey:[entryidarray objectAtIndex:indexpath.row] toDisk:YES completion:nil];
}else {
    NSLog(@"the image is nil");
}

【讨论】:

    猜你喜欢
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 2020-04-15
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多