Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用SDURLCache和AFN网络_Ios_Afnetworking - Fatal编程技术网

Ios 如何使用SDURLCache和AFN网络

Ios 如何使用SDURLCache和AFN网络,ios,afnetworking,Ios,Afnetworking,我是初学者。我对SDURLCache和AFNetworking有问题。我的代码: 首先,我在appdelegate.m中设置sdurlcache self.cache = [[SDURLCache alloc] initWithMemoryCapacity:1024*1024 // 1 MB mem cache diskCapacity:1024*1024*5 // 5 MB disk cache

我是初学者。我对SDURLCache和AFNetworking有问题。我的代码:

首先,我在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中使用了AfNetworking+UIImageView:

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

但图片不缓存。如果网络无效,如果您使用的是IOS5或更高版本,则图片不显示。NSURLCache会自动将响应保存到磁盘。所以你不需要SDURLCache。更多信息请参见Peter的博客帖子