删除图像缓存

时间:2014-08-27 10:07:46

标签: ios objective-c iphone caching afnetworking

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

使用具有相同网址的新图片时,无法清除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'用于类消息是一个前向声明

1 个答案:

答案 0 :(得分:3)

UIImageView af_sharedImageCache中的UIImageView (AFNetworking)制作@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 类别

<强> SPUtility.m

{{1}}