5

I need some help.

I use sd_setImageWithURL like tihs

     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

when I click Button I can get Log "stopDownloading Clicked" in stopDownloading function but sd_cancelCurrentImageLoad() didn't work.

just keep downloading and I can get Completed Log.

How can I stop downloading or cancel sd_setImageWithURL in progress ??

Thx.

Rajat
  • 10,977
  • 3
  • 38
  • 55
BRODY BYUN
  • 65
  • 6
  • Did you check the parameters of that completion block ? When you call stop what are the values of those params ? – Midhun MP Oct 05 '16 at 06:37

0 Answers0