我正在使用AfNetworking版本〜> 1.3.4,该版本由cocoaPods添加。而且我无法升级到2.0,因为我的应用程序中使用了大多数方法。
使用具有相同URL的新图像时,无法清除AFImageCache(在UIImageView + AFNetworking中)
我应该为此在“UIImageView + AFNetworking”类中添加以下方法。
+ (void)clearCachedImages {
[[[self class] af_sharedImageCache] removeAllObjects];
}
因为AFNetworking在我的cocoaPods中。我无法添加。
请帮我如何按类别/子类添加此方法?
编辑:
我尝试了以下
@class AFImageCache;
@interface SPUtility : NSObject
{
}
@end
@implementation SPUtility
+ (void)clearCachedImages {
[[AFImageCache af_sharedImageCache] removeAllObjects]; //shows following error
}
@end
错误:选择器“af_sharedImageCache”的未知类方法
2.类消息的接收者“AFImageCache”是一个前向声明
最佳答案
由于UIImageView
在af_sharedImageCache
中,因此为UIImageView (AFNetworking)
类别
SPUtility.m
@interface UIImageView (MyMethods)
+ (NSCache *)af_sharedImageCache;
@end
//you don't have to implement method since it's already defined in UIImageView (AFNetworking)
//It's just for the happiness of the compiler
@implementation SPUtility
+ (void)clearCachedImages {
[[UIImageView af_sharedImageCache] removeAllObjects];
}
@end
关于ios - 删除图像缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25524309/