SDImageCache - 4.0迁移后无法识别的选择器错误

时间:2017-07-10 19:48:27

标签: ios objective-c sdwebimage

我最近将一个项目升级到SDWebImage 4.0,我只用它来缓存图像然后检索它们。如果这在3.x版本上完美运行。迁移后我现在收到以下错误...

-[SDImageCache storeImage:forKey:toDisk:completion:]: unrecognized selector sent to instance 0x174097cf0

这似乎应该是一个简单的错误来解决,但经过多次尝试,我无法解决它。

以下是我以前的3.x API代码......

@property (strong, nonatomic) SDImageCache *imageCache;
- (SDImageCache *)imageCache {

    if (!_imageCache) {
        _imageCache = [[SDImageCache alloc] initWithNamespace:NAME_SPACE_IMAGE_CACHE];

    }

    return _imageCache;
}


    [self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES];

这是我更新的4.0 API代码,这是抛出错误的代码行...

[self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES completion:^{
                                    NSLog(@"INFO: Image cached successfully!");
                                }];

有人可以帮助澄清问题所在吗?

提前致谢!

2 个答案:

答案 0 :(得分:0)

我尝试这样并且它可以工作,你必须移动+ cmd + k然后重新构建,必须解决问题,如此处所指出的那样https://github.com/rs/SDWebImage/issues/1602

#import "ViewController.h"

@interface ViewController ()
@property SDImageCache * imageCache;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.imageCache = [SDWebImageManager sharedManager].imageCache;
    // Do any additional setup after loading the view, typically from a nib.
    [_imageCache storeImage:[UIImage imageNamed:@"test"] forKey:@"testKey" toDisk:YES completion:^{
        NSLog(@"INFO: Image cached successfully!");
    }];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
  

CONSOLE OUTPUT

     

2017-07-11 00:55:12.146 SDWebImageSOQuestion [17275:339149]信息:图片   缓存成功!

希望这有帮助

答案 1 :(得分:0)

我的广告连播更新到5.0时,我遇到了同样的问题。要修复它,我需要...

更改

[imageCache clearDisk];

收件人

[imageCache clearDiskOnCompletion:^{

}];