[英]SDWebImage Cancel download
I am using SDWebimage to load images on my tablkeview I am following this tutorial 我正在使用SDWebimage在我的tablkeview上加载图像我正在学习本教程
Now I stuck on a problem,If I scroll down and hit back before images get loaded the app got crashes.How can I solve this ? 现在我遇到了一个问题,如果我向下滚动并在图像加载之前回来,应用程序崩溃了。我怎么能解决这个问题?
How to cancel the SDWebImage download. 如何取消SDWebImage下载。 I have gone through some answers and discussions.But none of them helped me and could not use them
我已经经历了一些答案和讨论。但他们都没有帮助我,也无法使用它们
Please help me 请帮我
I am using 我在用
[cell.UserImage setImageWithURL:[NSURL URLWithString:[SDWebArray objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];
In your cell, you can cancel the image load if it's going to get re-used. 在您的单元格中,您可以取消图像加载,如果它将被重新使用。 In your
UITableViewCell
subclass add the following: 在您的
UITableViewCell
子类中添加以下内容:
-(void)prepareForReuse {
[super prepareForReuse];
[self.imageView cancelCurrentImageLoad]; // UIImageView for whatever image you need to cancel the loading for
}
Be sure to #import "UIImageView+WebCache.h"
as well. 一定要
#import "UIImageView+WebCache.h"
。
Though your app shouldn't be crashing, but I cannot help you without seeing some code, since it's not possible to pinpoint the cause of the crash from your description above. 虽然你的应用程序不应该崩溃,但是我没有看到一些代码就无法帮助你,因为你无法从上面的描述中找出崩溃的原因。
- (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];
SWIFT 4.0 SWIFT 4.0
self.imageView.sd_cancelCurrentImageLoad()
In case you are using SDWebImage Activity Indicator and wants to remove that as well 如果您正在使用SDWebImage活动指示器并想要删除它
self.imageView.sd_removeActivityIndicator()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.