6

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"]];
UnRewa
  • 2,462
  • 2
  • 29
  • 31
Vidya Vasudev
  • 81
  • 2
  • 5

4 Answers4

13

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.

runmad
  • 14,846
  • 9
  • 99
  • 140
  • I updated the question and add some code,as I said I am using this tutorial...http://iosmadesimple.blogspot.com/2013/04/lazy-image-loading.html – Vidya Vasudev Jun 21 '13 at 06:40
  • The code I provided above should solve it, did you try it? I think your crash is related to something different. What is the crash description? – runmad Apr 26 '14 at 15:11
3

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()
Muhammad Nayab
  • 1,612
  • 14
  • 14
  • 1
    `sd_removeActivityIndicator()` was removed in SDWebImage 5.0. Instead, you can use `self.imageView.sd_imageIndicator?.stopAnimatingIndicator()`. – Manabu Nakazawa Dec 11 '19 at 06:58
0
 - (void)cancelAll
{
    for (SDWebImageDownloader *downloader in downloaders) {
    [downloader cancel];
    }
    [cacheDelegates removeAllObjects];
    [cacheURLs removeAllObjects];

    [downloadInfo removeAllObjects];
    [downloadDelegates removeAllObjects];
    [downloaders removeAllObjects];
    [downloaderForURL removeAllObjects];
}
Himanshu Patel
  • 1,015
  • 8
  • 26
0

Put this line of code when your SDWebImage is already loaded:

[self.imageView cancelCurrentImageLoad];
Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
amit_donga
  • 224
  • 1
  • 9