ios - 删除图像缓存

标签 ios objective-c iphone caching afnetworking

我正在使用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”是一个前向声明

最佳答案

由于UIImageViewaf_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/

相关文章:

ios - 移动 View 并更改 uiimageview 的图像不执行 View 的移动

objective-c - 如何播放简单的系统声音

ios - 在 iOS 上使用智能卡进行 TLS 身份验证

objective-c - 提取音频 objective-c

iphone - 从登录 UIAlertView 取消时,应用内购买不会发送 SKPaymentCancelled

ios - 检查字符串中是否有违禁单词

objective-c - UITableView 中单元格的右侧 CellIdentifier

ios - 读取自定义框架中的 info.plist

iphone - 在 Quartz (iPhone SDK) 中绘制(打印 - 不是图表)方程

iphone - 为什么我不能编写 EKEvent 标题?