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.
What I do is store my images in a image cache like so.
Once I have fetched my image(s) from where ever, I store the UIImage in my imageCache array.
Then I store the filename in my cell data obj.
Store the data in obj and store obj in array. This will be used later to fetch your data.
Then you can set the image like so.
That should get you going in the right direction. I think there might be some syntax issues, I wrote this on a computer without Xcode. Happy Coding.