SDWebImage操作未被取消

我有一个表格视图,其中包含几个饲料细胞,每个饲料细胞有一个图片的几个图像。 我正在加载像这样的图像:

[timeLineCell.avatar setImageWithURL:[NSURL URLWithString:[feedAccount accountAvatarUrl]] placeholderImage:avatarPlaceholderImage options:SDWebImageRetryFailed]; 

这工作正常,但在缓慢的连接操作往往只是攀登而不是删除旧操作相同的图像。 也就是说,如果我向下滚动并通过相同的单元格进行备份,则会在操作队列中将相同的图像添加到第二,第三,第四等时间。

我也试图从cellForRow中像这样重用单元格时从下载队列中删除图像:

 - (void)prepareForReuse { [super prepareForReuse]; [self.avatar cancelCurrentImageLoad]; } 

但似乎操作不匹配SDWebImage的方法中的操作队列中的任何东西,所以它实际上并没有取消任何东西。 如果我在共享pipe理器上运行cancelAll,它显然不起作用,但显然不理想。

我知道我只在这个单元上显示一个图像,但是我已经注释掉了除这个图像加载之外的所有东西,问题依然存在。 如果我注释掉头像图像并允许不同的图像(以相似方式加载)下载,它也会持续下去。

任何人有任何提示呢?

PS我试过把SDWebImageRetryFailed的选项SDWebImageRetryFailed其他东西,包括没有选项,但是没有什么区别。

PPS我正在使用CocoaPods上提供的最新版本的SDWebImage(3.4)。

为了解决这个问题,我实际上编辑了一下SDWebImage框架。 首先,我将以下方法添加到SDWebImageManager

 - (void)cancelOperation:(id<SDWebImageOperation>)operation { @synchronized(self.runningOperations) { [self.runningOperations removeObject:operation]; } } 

然后,我修改了SDWebImageCombinedOperation上的- (void)cancel方法:

 - (void)cancel { self.cancelled = YES; [[SDWebImageManager sharedManager] cancelOperation:self]; if (self.cacheOperation) { [self.cacheOperation cancel]; self.cacheOperation = nil; } if (self.cancelBlock) { self.cancelBlock(); self.cancelBlock = nil; } } 

这并没有完全消除在队列上增加额外操作的问题,但是现有的失败的问题肯定会被清理得更快,这样问题就不再是问题了。 我假设看起来有更多的操作被添加到队列中,但这是因为现有的还没有检查他们isCancelled标志呢。

我也有这个问题很长一段时间。 我真的不知道为什么这个策略不起作用,因为它看起来应该是真的。 我通过从同一个框架切换到另一个API方法解决了这个问题。 我改用downloadWithURL:options:progress:而不是使用简写的UIImageView类别方法。

这是我在我的UITableViewCell类中结束了:

 @interface MyTableViewCell () @property (nonatomic, weak) id <SDWebImageOperation> imageOperation; @end @implementation MyTableViewCell - (void)prepareForReuse { [super prepareForReuse]; if (self.imageOperation) { [self.imageOperation cancel]; } self.imageOperation = nil; [self.imageView setImage:self.placeholderImage]; } - (void)configure { SDWebImageManager *manager = [SDWebImageManager sharedManager]; self.imageOperation = [manager downloadWithURL:self.imageURL options:SDWebImageRetryFailed progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { if (image) { [self.imageView setImage:image]; } }]; } @end