I am working on a UITableView that is very much like the iOS's native Photo app: it has many rows with 4 image thumbnails in each row. (i.e. each UITableViewCell has 4 UIImageViews) All thumbnails loaded from Core Data.
I have revised my implementation multiple times and I can see performance improvements, but it is still unable to scroll as smooth as the Photo app.
I need advise on how to properly cache the photos for best performance. This is what I tried:
1. My first attempt (extremely lag when scrolling)
- Images are stored with type Transformable in CoreData.
- In cellForRow function, each image is fetched from CoreData on the
fly.
2. Second attempt (faster, but still lag a bit when scrolling)
- Images are stored with type Binary Data with 'external storage' option ticked in CoreData.
- In cellForRow function, each image is first loaded from Core Data and then stored into NSCache in memory, so next time cellForRow fires, we will use the UIImage from NSCache directly if available.
After using NSCache to cache images loaded from CoreData, scrolling is visibly faster but since images still have to be loaded from CoreData when it is not yet available in NSCache, scrolling will still be jerky from times to times.
So, there must be a better way, I could preload all the images into memory but since there might be large number or rows of images so I didnt plan to preload the images at all.
What else can I do to load the image faster in cellForRowAtIndexPath?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…