【问题标题】:Remove Image Cache删除图像缓存
【发布时间】:2014-10-20 20:53:04
【问题描述】:

我用的是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'是一个转发声明

【问题讨论】:

  • 为什么无法添加。转到 pod 项目并打开该文件并添加此方法。你面临什么困难
  • 因为将来如果我更新 pod,我的方法将丢弃。它会恢复原状。

标签: ios objective-c iphone caching afnetworking


【解决方案1】:

为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

【讨论】:

  • 它告诉我:“af_sharedImageCache”找不到。可以请具体一点。
  • 是的,因为它没有在头文件中声明,所以忽略警告
  • 请检查上面的编辑部分..@Inder
  • 是的,它有效.. 谢谢。太感谢了。我从早上就被困住了。
  • 这是我的荣幸 :) ,记住一件事,目标 c 中的每个方法都是公共的,如果存在,您可以调用任何方法。 :)
猜你喜欢
  • 2013-01-14
  • 1970-01-01
  • 2013-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-09
  • 2017-03-14
  • 2023-03-10
相关资源
最近更新 更多