iOS-SDWebImage)我可以取消正在进行的sd_setImageWithURL吗?

时间:2016-10-05 06:25:37

标签: ios sdwebimage

我需要一些帮助。

我使用像tihs

这样的sd_setImageWithURL
     self.downloadButton.addTarget(self, action: #selector(self.stopDownloading), forControlEvents: .TouchUpInside)

    self.imageView.sd_setImageWithURL(NSURL(string:myURL!)!, placeholderImage: UIImage(named: "placeHolderImage"), options: SDWebImageOptions.ProgressiveDownload , progress: {
        (receivedSize: Int!, expectedSize: Int!) in

        if(receivedSize > 0 )
        {
            self.percentString = String(format: "%.0f",(Float(receivedSize) / Float(expectedSize) * 100))
            [self.downloadProgress.setProgress(Float(receivedSize) / Float(expectedSize), animated: true)]
            self.downloadStateLabel.text = "\(receivedSize/1000000) / \(expectedSize/1000000)MB (\(self.percentString)%)"
            NSLog("%@", self.percentString)
        }

        }, completed: {
            (image, error, cacheType, url) in
            NSLog("Completed'");

    })
func stopDownloading(sender: AnyObject)
{
    NSLog("stopDownloading Clicked")
    self.imageView.sd_cancelCurrentImageLoad()

}

enter image description here

当我单击Button时,我可以在stopDownloading函数中获取Log“stopDownloading Clicked”,但sd_cancelCurrentImageLoad()不起作用。

继续下载,我可以获得完成日志。

如何停止下载或取消正在进行的sd_setImageWithURL?

THX。

0 个答案:

没有答案