我最近将一个项目升级到 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!");
}];
有人可以帮助澄清问题所在吗?
提前致谢!
我尝试这样并且它有效,您必须 shift + 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] INFO: Image cached successfully!
希望对你有帮助
关于ios - SDImageCache - 4.0 迁移后无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45020422/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |