【问题标题】:SDWebImage Cancel downloadSDWebImage 取消下载
【发布时间】:2013-06-20 19:42:41
【问题描述】:

我正在使用 SDWebimage 在我的 tablkeview 上加载图像 我在关注this教程

现在我遇到了一个问题,如果我在加载图像之前向下滚动并回击,应用程序就会崩溃。我该如何解决这个问题?

如何取消 SDWebImage 下载。 我经历了一些答案和讨论。但没有一个能帮助我,也无法使用它们

请帮帮我

我正在使用

  [cell.UserImage setImageWithURL:[NSURL URLWithString:[SDWebArray objectAtIndex:indexPath.row]]  placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];

【问题讨论】:

  • 你解决了吗?或者....

标签: iphone ios objective-c sdwebimage


【解决方案1】:

在您的单元格中,如果要重新使用图像加载,您可以取消它。在您的 UITableViewCell 子类中添加以下内容:

-(void)prepareForReuse {
    [super prepareForReuse];
    [self.imageView cancelCurrentImageLoad]; // UIImageView for whatever image you need to cancel the loading for
}

请务必同时#import "UIImageView+WebCache.h"

虽然您的应用程序不应该崩溃,但如果没有看到一些代码,我无法帮助您,因为无法从您上面的描述中查明崩溃的原因。

【讨论】:

【解决方案2】:

SWIFT 4.0

self.imageView.sd_cancelCurrentImageLoad()

如果您正在使用 SDWebImage 活动指示器并且想要删除它

self.imageView.sd_removeActivityIndicator()

【讨论】:

  • sd_removeActivityIndicator() 在 SDWebImage 5.0 中被删除。相反,您可以使用self.imageView.sd_imageIndicator?.stopAnimatingIndicator()
【解决方案3】:
 - (void)cancelAll
{
    for (SDWebImageDownloader *downloader in downloaders) {
    [downloader cancel];
    }
    [cacheDelegates removeAllObjects];
    [cacheURLs removeAllObjects];

    [downloadInfo removeAllObjects];
    [downloadDelegates removeAllObjects];
    [downloaders removeAllObjects];
    [downloaderForURL removeAllObjects];
}

【讨论】:

    【解决方案4】:

    当你的 SDWebImage 已经加载时,输入这行代码:

    [self.imageView cancelCurrentImageLoad];
    

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-31
      相关资源
      最近更新 更多