How to cancel download with SDWebImageDownloader

大城市里の小女人 提交于 2019-12-11 12:35:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22914624/how-to-cancel-download-with-sdwebimagedownloader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!