Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 未取消SDWebImage操作_Iphone_Ios_Sdwebimage - Fatal编程技术网

Iphone 未取消SDWebImage操作

Iphone 未取消SDWebImage操作,iphone,ios,sdwebimage,Iphone,Ios,Sdwebimage,我有一个表视图,其中包括几个提要单元格,每个单元格都有一些图像。我正在加载这样的图像: [timeLineCell.avatar setImageWithURL:[NSURL URLWithString:[feedAccount accountAvatarUrl]] placeholderImage:avatarPlaceholderImage options:SDWebImageRetryFailed]; 这很好,但在连接速度较慢的情况下,操作往往只是爬升,而不是删除相同映像的旧操作。也就是

我有一个表视图,其中包括几个提要单元格,每个单元格都有一些图像。我正在加载这样的图像:

[timeLineCell.avatar setImageWithURL:[NSURL URLWithString:[feedAccount accountAvatarUrl]] placeholderImage:avatarPlaceholderImage options:SDWebImageRetryFailed];
这很好,但在连接速度较慢的情况下,操作往往只是爬升,而不是删除相同映像的旧操作。也就是说,如果我向下滚动并向上滚动相同的单元格,它会在第二次、第三次、第四次等时间将相同的图像添加到操作队列中

我还尝试在cellForRow中重复使用单元格时从下载队列中删除图像:

- (void)prepareForReuse {
    [super prepareForReuse];
    [self.avatar cancelCurrentImageLoad];
}
但该操作似乎与SDWebImage方法中的操作队列中的任何内容都不匹配,因此它实际上不会取消任何内容。如果我在共享管理器上运行cancelAll,它可以工作,但显然并不理想

我知道我在这个单元格上只显示了一个图像,但是我已经注释掉了除了这个图像加载之外的所有内容,问题仍然存在。如果我注释掉化身图像并允许下载不同的图像(类似加载),它也会持续存在

有人对此有什么建议吗

另外,我尝试过将选项从
SDWebImageRetryFailed
更改为其他选项,包括完全没有选项,但没有任何区别


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

我也有这个问题很久了。我真的不知道为什么这个策略不起作用,因为它似乎真的应该起作用。我通过从同一框架切换到另一个API方法解决了这个问题。我没有使用简写的UIImageView分类方法,而是改为使用URL:options:progress:completed下载

这就是我在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
@interface MyTableViewCell()
@属性(非原子,弱)id imageOperation;
@结束
@MyTableViewCell的实现
-(无效)预先准备{
[预先超级准备];
if(自映像操作){
[自映像操作取消];
}
self.imageOperation=nil;
[self.imageView setImage:self.placeholderImage];
}
-(void)配置{
SDWebImageManager*manager=[SDWebImageManager共享管理器];
self.imageOperation=[manager downloadWithURL:self.imageURL
选项:SDWebImageRetryFailed
进展:零
已完成:^(UIImage*图像,N错误*错误,SDImageCacheType cacheType,布尔已完成){
如果(图像){
[self.imageView setImage:image];
}
}];
}
@结束

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

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

这并没有完全消除在队列上添加额外操作的问题,但是现有的失败操作肯定会更快地被清除,因此问题不再是问题。我假设队列中似乎添加了更多操作,但这是因为现有操作尚未检查其
isCancelled
标志。

有趣的是,它与该方法一起工作。我提出了一个有效的解决方案,虽然不能完全解决问题,但似乎可以大大缓解问题。我马上就把它贴上去。
- (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;
    }
}