0xS*_*ina 6 cocoa-touch objective-c ios sdwebimage
我正在努力加载一堆图像:
for (NSDictionary *s in things) {
[manager downloadWithURL:[NSURL URLWithString:s[photo]]
options:0
progress:nil
completed:nil];
}
Run Code Online (Sandbox Code Playgroud)
它不是下载这些图像.但是,如果我传入一个空的完成块,就像这样:
for (NSDictionary *s in things) {
[manager downloadWithURL:[NSURL URLWithString:s[photo]]
options:0
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { }];
}
Run Code Online (Sandbox Code Playgroud)
然后它工作得很好.我的问题是:为什么?有一个更好的方法吗?传入空座对我来说似乎不对.
Gab*_*lla 19
您使用的API不正确.
要预取图像并将它们存储在缓存中,请使用SDWebImagePrefetcher它.
NSMutableArray * urls = [NSMutableArray arrayWithCapacity:things.count];
for (NSDictionary *s in things) {
[urls addObject:[NSURL URLWithString:s[photo]]];
}
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:urls];
Run Code Online (Sandbox Code Playgroud)
作为旁注,我提交了一个拉取请求 - 刚刚合并 - 以强制执行completedBlock您(错误)使用的API,以便其他程序员不会让您陷入同样的错误.
| 归档时间: |
|
| 查看次数: |
3305 次 |
| 最近记录: |