I am trying to avoid rendering delays in UICollectionViewController by pre-caching subviews of cell contentView in NSCache but it seems I miss to activate them properly since there is a delay in rendering cell when user scrolls to it (scrolling freezes, but first time only!). When user comes back, the same view is rendered smoothly. So it seems that pre-caching a simply initialized view is not enough and I need to do something more with the view in order to render it faster. How do I do it?
The current flow is the following:
- Render collection view with 10 cells and pre-cache all 10 cell views (i.e. cachedView -> contentView -> cellView)
- Scroll forward through the first 5 cells seeing rendering/scrolling delays
- Scroll backward to the first cell smoothly, no delays
- Scroll forward again through the first 5 cells smoothly, no delays
- Scroll forward through remaining cells seeing rendering delays
- At this point all cell views are activated(?) so scrolling backward and forward is smooth.
Some details:
- A cell takes the whole screen.
cellForItemAtIndexPath
replaces cached view (removescell.contentView.subviews.first
and adds another view from cache)- Cached view contains images.
- Rendering the cached views to an image before scrolling does NOT speed up rendering cells.
- Not using cached views leads to rendering/scrolling delays all the time