问题
I am using SDWebimage to load images on my tablkeview I am following this tutorial
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. 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"]];
回答1:
In your cell, you can cancel the image load if it's going to get re-used. In your UITableViewCell
subclass add the following:
-(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.
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.
回答2:
- (void)cancelAll
{
for (SDWebImageDownloader *downloader in downloaders) {
[downloader cancel];
}
[cacheDelegates removeAllObjects];
[cacheURLs removeAllObjects];
[downloadInfo removeAllObjects];
[downloadDelegates removeAllObjects];
[downloaders removeAllObjects];
[downloaderForURL removeAllObjects];
}
回答3:
Put this line of code when your SDWebImage
is already loaded:
[self.imageView cancelCurrentImageLoad];
回答4:
SWIFT 4.0
self.imageView.sd_cancelCurrentImageLoad()
In case you are using SDWebImage Activity Indicator and wants to remove that as well
self.imageView.sd_removeActivityIndicator()
来源:https://stackoverflow.com/questions/17222434/sdwebimage-cancel-download