Reuse Cell issue: collection view fetching all image from local

Hi,

I’ve fetching images from local for AllPhotos similar to https://www.raywenderlich.com/11764166-getting-started-with-photokit
And then I reloaded it in collection View. Here is some problem:

  • first time load the image position is not right. Some of the image got wrong position
  • after scrolling, some image position is messed up too

I’ve searched a lot place and found out this is some reuse cell issue. and one of the solution is to clean the old cell inside prepareForReuse func.(but seems this totally abandan reuse cell feature? and might be slow for large amount of data?)

Is there any way to handle reuse cell issue properly with large amount of data. for example 20000 locally image loading?

any one can help???

@o1xhack Thanks very much for your question!

I believe what you need to be doing is caching the images as you scroll. The reason for this is so that you are not retrieving these images repeatedly, thus minimizing the network calls, and consequently, the data consumption. You also improve performance in doing so. As the images are retrieved, store them locally using NSCache, and this way, prior to retrieving the images from the network, check to see if the image is already stored locally. If the image exists, then simply retrieve it from local storage. If it doesn’t exist, then and only then retrieve the image from the network, and then store it locally right away for later reuse. I believe this will solve your issue.

I hope this helps!

All the best.

This topic was automatically closed after 166 days. New replies are no longer allowed.