I'm using the Haneke library to download, load & cache images. This works great, except when scrolling too fast, it loads the incorrect image, or sometimes no image at all.
It is scrolling faster than it can download in the background, so whatever image is next in the queue, can be loaded into the incorrect cell.
Here is the code for requesting the images over the network & from cache.
let fetcher_net = NetworkFetcher<UIImage>(URL: finished_URL!)
let fetcher_disk = DiskFetcher<UIImage>(path: check_apost)
cache.fetch(fetcher: fetcher_disk).onSuccess { image in
//cell.card_imageIV.hnk_fetcher.cancelFetch()
//print("Image Cache found")
cell.card_imageIV.image = image
}.onFailure{ image in
//print("Unavailable to find image cache, fetching from network")
cache.fetch(fetcher: fetcher_net).onSuccess { image in
//print("Network image request SUCCESS")
cell.card_imageIV.image = image
}
}
Also, in the custom cell Swift file, is there anything I can put in the following method that will stop any request when cells are off the screen?
override func prepareForReuse() {
super.prepareForReuse()
// Increment the generation when the cell is recycled
//card_imageIV.hnk_cancelSetImage()
//card_imageIV.image = nil
}
I've been trying to figure this out for weeks. If anyone has better libraries to use to fix this issue, let me know.