I just started using KingFisher.
When you scroll too fast down a UITableView, all network/doadload request get backed up, so by time it stops scrolling, it's still finishing those previous request.
This leads to all the images flickering around with different pictures until all backed up requests are complete.
Here is my code to retrieve images from cache or network.
if ImageCache.defaultCache.cachedImageExistsforURL(finished_URL!) == true {
print("image is already cached.")
if cell.tag == indexPath.row{
cell.card_imageIV.image = UIImage(imageLiteral: "ic_error")
KingfisherManager.sharedManager.retrieveImageWithURL(finished_URL!, optionsInfo: nil, progressBlock: nil, completionHandler: { (image, error, cacheType, imageURL) -> () in
cell.card_imageIV.image = image
print("Retrieved cached image")
})
}
}else{
cell.card_imageIV.kf_setImageWithURL(finished_URL!, placeholderImage: self.placeholderImage, optionsInfo: nil, completionHandler: { image, error, cacheType, imageURL in
print("\(card_name): Finished")
})
}
I've tried following documentation on https://github.com/onevcat/Kingfisher for cancelling all previous download tasks, using but didn't help.
Following code I tried:
// The image retrieving will stop.
imageView.kf.cancelDownloadTask()
This only cancels the current cells, at least from I can make sense of.
I have absolutely same issue with my project. I am looking for a way to implement just the same thing as you want: if I scroll VERY fast, – I want to cancel previous downloads. Here is my approach for this, using KingFisher library(Swift 3):
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentify)
cell?.imageView?.kf.cancelDownloadTask()
}
This method must be declared in table view delegate. It will cancel download task task of already scrolled cell.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With