Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDWebImage Cancel download

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"]];
like image 689
Vidya Vasudev Avatar asked Jun 20 '13 19:06

Vidya Vasudev


2 Answers

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.

like image 102
runmad Avatar answered Oct 23 '22 11:10

runmad


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()
like image 22
Muhammad Nayab Avatar answered Oct 23 '22 10:10

Muhammad Nayab