Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用yy_cancelCurrentImageRequest取消当前图片的请求似乎不起作用 #79

Closed
ufosky opened this issue Mar 26, 2016 · 7 comments
Closed
Labels

Comments

@ufosky
Copy link

ufosky commented Mar 26, 2016

我在UICollectionViewCell里面用下面代码加载图片

[imageView yy_setImageWithURL:[NSURL URLWithString:avatarUrl] placeholder:[UIImage imageNamed:@"ic_message_del_robot"] options:YYWebImageOptionAvoidSetImage progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
  if (!error && stage == YYWebImageStageFinished) {
    imageView.image = image;
    imageView.backgroundColor = [UIColor clearColor];
  }
}];

在prepareForReuse里面取消加载

[imageView yy_cancelCurrentImageRequest];

可是我发现有时候一个图片已经取消了结果还是得到回调了,在网络慢的时候就有可能出现前一个图片已经取消,结果在后一个图片回调之后运行前一个图片的回调,结果就是图片错了

@ibireme
Copy link
Owner

ibireme commented Mar 26, 2016

在 Demo 中不能复现。。

yy_cancelCurrentImageRequest 这个方法,可以看一下源码,内部会同步 cancel 掉各种操作。

@ufosky
Copy link
Author

ufosky commented Mar 27, 2016

这是我修改的demo,可以复现这个问题,可以快速不停的点reload,出现问题的时候会抛出异常,有详细的请求顺序的日志

YYWebImageExample.m.zip

@ibireme ibireme added the bug label Mar 27, 2016
@ibireme
Copy link
Owner

ibireme commented Mar 27, 2016

仔细调试了一下,貌似是在系统繁忙的时候,completion block 已经提交到主线程,但还未执行时,operation 被 cancel 了。我改一下。。

@ibireme
Copy link
Owner

ibireme commented Mar 27, 2016

Fixed.

@ibireme ibireme closed this as completed Mar 27, 2016
@ufosky
Copy link
Author

ufosky commented Mar 27, 2016

我更新了试了一下,还是可能出现,可以看看这里weakSetter一直是nil
https://github.com/ibireme/YYWebImage/blob/master/YYWebImage/Categories/UIImageView%2BYYWebImage.m#L158

@ufosky
Copy link
Author

ufosky commented Mar 28, 2016

把181行提到block定义前面或者153行加上__block修饰就好了

@ibireme
Copy link
Owner

ibireme commented Mar 28, 2016

Thanks~

@ibireme ibireme closed this as completed Mar 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants