删除图像缓存

问题描述:

我正在使用AfNetworking版本〜> 1.3.4,它是由cocoaPods添加的。我无法升级到2.0,因为我的应用程序中使用了大多数方法。删除图像缓存

AFImageCache(在的UIImageView + AFNetworking)时具有相同URL的新图像被用于

不能被清除我应该添加以下方法中的“的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' 的类消息为转发宣言

+0

你为什么无法添加。转到pod项目并打开该文件并添加此方法。如果我更新吊舱,我的方法将会丢弃,您将面临哪些困难 – 2014-08-27 10:36:29

+0

becoz。它会回到原来的。 – Myaaoonn 2014-08-27 10:57:24

作为UIImageView的一个类别,因为您的af_sharedImageCache在​​

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 
+0

它显示我:“af_sharedImageCache”找不到。可以plz具体。 – Myaaoonn 2014-08-27 11:07:43

+0

是的,因为它没有在头文件中声明,所以只是忽略警告 – 2014-08-27 11:10:33

+0

请检查上面的编辑部分.. @Inder – Myaaoonn 2014-08-27 11:21:19