SDWebImage取消下载
我正在使用SDWebimage在我的tablkeview上加载图像我正在学习本教程
现在我遇到了一个问题,如果我向下滚动并在图像加载之前回来,应用程序崩溃了。我怎么能解决这个问题?
如何取消SDWebImage下载。 我已经经历了一些答案和讨论。但他们都没有帮助我,也无法使用它们
请帮帮我
我在用
[cell.UserImage setImageWithURL:[NSURL URLWithString:[SDWebArray objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];
在您的单元格中,您可以取消图像加载,如果它将被重新使用。 在您的UITableViewCell
子类中添加以下内容:
-(void)prepareForReuse { [super prepareForReuse]; [self.imageView cancelCurrentImageLoad]; // UIImageView for whatever image you need to cancel the loading for }
一定要#import "UIImageView+WebCache.h"
。
虽然你的应用程序不应该崩溃,但是如果没有看到一些代码我就无法帮助你,因为你无法从上面的描述中找出崩溃的原因。
- (void)cancelAll { for (SDWebImageDownloader *downloader in downloaders) { [downloader cancel]; } [cacheDelegates removeAllObjects]; [cacheURLs removeAllObjects]; [downloadInfo removeAllObjects]; [downloadDelegates removeAllObjects]; [downloaders removeAllObjects]; [downloaderForURL removeAllObjects]; }
在加载SDWebImage
时放入以下代码行:
[self.imageView cancelCurrentImageLoad];