gpt4 book ai didi

objective-c - SDWebImage - setImageWithURL加载完成后执行任务的方法

转载 作者:行者123 更新时间:2023-11-29 11:19:27 25 4
gpt4 key购买 nike

正如标题所说。鉴于:

[imageView setImageWithURL:[NSURL URLWithString:imageurl]];

图像加载(或从缓存中提取)并显示后执行任务的最佳方式是什么?

最佳答案

setImageWithURL API 是一种非常方便的方法,但您需要更多的控制,所以我建议您自己加载图像(很大程度上受到 https://github.com/rs/SDWebImage/blob/master/README.md 的启发):

SDWebImageManager *manager = [SDWebImageManager sharedManager];
UIImage *cachedImage = [manager imageWithURL:url];

if (cachedImage) {
[imageView setImage:cachedImage];
[self doMyOtherCustomStuff];
} else {
[manager downloadWithURL:url delegate:self];
}

...

- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image
{
[imageView setImage:image];
[self doMyOtherCustomStuff];
}

祝你好运!

关于objective-c - SDWebImage - setImageWithURL加载完成后执行任务的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7970531/

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