문제

I'm using SDWebImageDownloader to download an image and then show it on a cell, but I have the issue that if the image doesn't finish download once the view is unloaded, it causes that my app crashes.

I'm using the code that is provided on the github page:

[SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
                                                options:0
                                               progress:^(NSInteger receivedSize, NSInteger expectedSize)
                                               {
                                                   // progression tracking code
                                               }
                                               completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
                                               {
                                                   if (image && finished)
                                                   {
                                                       // do something with image
                                                   }
                                               }];

And in this github issue, a user says that this method returns a SDWebImageOperation, which can be cancelled, but I couldn't find a way to do cancel all the operations on the shared downloader.

도움이 되었습니까?

해결책

You may want to use an instance of SDWebImageManager instead, which includes methods for cancelling requests.

If you're showing the image in a UIImageView in a cell, however, you should just use the UIImageView (WebCache) class which extends UIImageView and allows you to cancel images you're loading with the method - (void)cancelCurrentImageLoad;.

You should use that method in UITableViewCell's prepareForReuse method.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top