1

就像标题所说的那样。鉴于:

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

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

4

2 回答 2

2

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];
}

祝你好运!

于 2011-11-01T18:03:54.920 回答
0

一种选择是实施SDWebImageManagerDelegate协议。文档中有一个示例SDWebImage

另一种选择是使用 KVO 并imageimageView.

于 2011-11-01T17:56:05.077 回答