如何使用SDURLCache和AFNetworking

时间:2013-01-10 05:37:45

标签: ios afnetworking

我是初学者。我有关于SDURLCache和AFNetwoking.my代码的问题:

首先,我在appdelegate.m中设置了sdurlcache

self.cache = [[SDURLCache alloc] initWithMemoryCapacity:1024*1024 // 1 MB mem cache
                                           diskCapacity:1024*1024*5 // 5 MB disk cache
                                               diskPath:[SDURLCache defaultCachePath]];
self.cache.ignoreMemoryOnlyStoragePolicy = YES;
[NSURLCache setSharedURLCache:self.cache];

第二,我在tableCell中使用AFNetwoking + UIImageView:

 [cell.Image setImageWithURL:url placeholderImage:[UIImage imageNamed:@"zhanweiSmall.png"]];

但是图片没有缓存。如果网络无效,图片不显示

1 个答案:

答案 0 :(得分:0)

如果您使用的是IOS5或更高版本,NSURLCache会自动将响应保存到磁盘。所以你不需要SDURLCache。有关详细信息,请参阅Peter的博客文章。

http://petersteinberger.com/blog/2012/nsurlcache-uses-a-disk-cache-as-of-ios5/