【问题标题】:Wait till setImageWithURL is loaded SDWebImage等到 setImageWithURL 加载 SDWebImage
【发布时间】:2014-07-20 20:10:15
【问题描述】:

我需要等到setImageWithURL 完成图像处理,这是我在 viewDidLoad 方法上的代码:

UIImageView *test = [[UIImageView alloc] init];
[test setImageWithURL:[NSURL URLWithString:object.imageUrl]];

是否可以将此方法设置为同步运行?我已经尝试过 completed 块,但出于某种奇怪的原因,它永远不会被调用。

【问题讨论】:

标签: ios caching uiimageview uiimage sdwebimage


【解决方案1】:

据我所知,SDWebImage 没有同步下载/设置图像的方法(原因很明显)。但是,如果您的用例希望您使用同步方法,请尝试以下操作:

UIImageView *test = [[UIImageView alloc] init];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
[test setImage:image];

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    相关资源
    最近更新 更多