gpt4 book ai didi

ios - SDWebImage 急切加载图像

转载 作者:可可西里 更新时间:2023-11-01 03:36:33 25 4
gpt4 key购买 nike

我正在尝试加载一堆图像:

for (NSDictionary *s in things) {
[manager downloadWithURL:[NSURL URLWithString:s[photo]]
options:0
progress:nil
completed:nil];
}

它不是在下载这些图像。但是,如果我传入一个空的完成 block ,如下所示:

for (NSDictionary *s in things) {
[manager downloadWithURL:[NSURL URLWithString:s[photo]]
options:0
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { }];
}

然后它工作得很好。我的问题是:为什么?有一个更好的方法吗?传入一个空 block 对我来说似乎不正确。

最佳答案

您使用的 API 不正确。

要预取图像并将它们存储在缓存中,请使用专门用于此目的的 SDWebImagePrefetcher

NSMutableArray * urls = [NSMutableArray arrayWithCapacity:things.count];
for (NSDictionary *s in things) {
[urls addObject:[NSURL URLWithString:s[photo]]];
}
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:urls];

作为旁注,我提交了一个拉取请求——刚刚被合并——以强制在你正在(误)使用的 API 中存在 completedBlock,这样其他程序员就不会让你犯同样的错误。

关于ios - SDWebImage 急切加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18509624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com