我需要帮助。
我像 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'");
})
Run Code Online (Sandbox Code Playgroud)
func stopDownloading(sender: AnyObject)
{
NSLog("stopDownloading Clicked")
self.imageView.sd_cancelCurrentImageLoad()
}
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,我可以在 stopDownloading 函数中得到日志“stopDownloading Clicked”,但 sd_cancelCurrentImageLoad() 不起作用。
只要继续下载,我就可以获得已完成的日志。
如何停止下载或取消正在进行的 sd_setImageWithURL ?
谢谢。