I am working on a UITableView, which is very similar to the native iOS app for photos: it has many lines with 4 thumbnails of images on each line. (i.e. each UITableViewCell has 4 UIImageViews). All thumbnails are loaded from the master data.
I reviewed my implementation several times, and I see performance improvements, but it still cannot scroll as smoothly as the Photos application.
I need to advise how to cache photos properly for better performance. This is what I tried:
1. My first attempt (extremely lag while scrolling)
- Images are saved with the Transformable type in CoreData.
- In the cellForRow function, each image is extracted from CoreData on a fly.
2. The second attempt (faster, but still slightly behind when scrolling)
- Images are saved with binary data type with the option “external storage” marked in CoreData.
- In the cellForRow function, each image is first loaded from Core Data and then stored in NSCache in memory, so the next time cellForRow is launched, we will use UIImage from NSCache directly if it is available.
After using NSCache to cache images loaded from CoreData, scrolling is noticeably faster, but since images still need to be loaded from CoreData when they are not yet available in NSCache, scrolling will still be distracted from time to time.
So, there should be a better way, I could preload all the images into memory, but since there may be a large number or lines of images, so I did not plan to preload the images at all.
What else can I do to load an image faster in cellForRowAtIndexPath?
objective-c uitableview
mkto
source share