在UIImageView+AFNetworking的头文件中加入静态方法
UIImageView+AFnetworking.h
+ (void)clearCache;
+ (void)clearCacheWithURL:(NSURL *)url;
UIImageView+AFNetworking.m
//清除所有缓存+ (void)clearCache
{
AFImageCache *cache = (AFImageCache *)[UIImageView sharedImageCache];
[cache removeAllObjects];
return;
}
//清除URL对应图片地址的缓存
+ (void)clearCacheWithURL:(NSURL *)url
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
AFImageCache *cache = (AFImageCache *)[UIImageView sharedImageCache];
[cache removeObjectForKey:[[request URL] absoluteString]];
}
//------------------------------
调用方法:加入头文件后
[UIImageView clearCache]; //清除所有缓存
[UIImageView clearCacheWithURL:url]; //清除URL对应图片地址的缓存