There is a TableView with Cells and there is ImageView in each of them. I use SDWebImage to load images and it works fine, but when I scroll fast - I see that images in cells are changing few times before it will be right image.
Why is it happening? What should I do?
p.s. I tried use it with or without placeholder with same result
imageView.sd_setImage(with: URL(string : myImageURL), placeholderImage: UIImage(named: "default.jpg"))
In your prepareForReuse() try adding:
imageView.sd_cancelCurrentImageLoad()
It will cancel the previous image downloading and then it won't happen.
Also, I would suggest using the sd_setImage with the completion block, that way you can also make sure it loads correctly.
// This will prevent sdwebimage load wrong url
guard let imgUrl = "Your image url.jpg" else { return }
imageView.sd_setImage(with: URL(string: imgUrl), placeholderImage: UIImage(named: "Your placeholder image.png"))
// Or you can match the url using this code, so the downloader won't catch the wrong url
if imgUrl == "Your image url" {
imageView.sd_setImage(with: URL(string: imgUrl), placeholderImage: UIImage(named: "Your placeholder image.png"))
}
// This is will clean your UIImageView, and cancel download progress when cell is not visible (will reuse)
class YourCell: UITableViewCell {
override prepareForReuse() {
imageView.sd_cancelCurrentImageLoad()
imageView.image = nil
}
}
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