I have built a tv guide style application for someone that utilizes a UICollectionView with a custom UICollectionViewLayout. The custom layout uses four different custom UICollectionViewCells. I have run into a very interesting problem that has stumped me and my team. My post is quite long, but it is done that way to hopefully give you the full context. If you have the time to read and toss me your ideas. I would greatly appreciate it. As always, thanks to the SO community for all your help.
tl;dr - UICollectionView with custom layout (subclass of UICollectionViewLayout) randomly loses all data in the view. Goes completely blank. .reloadData()
is called on viewDidAppear
and does not fix. Stumped as to the cause.
Section 0, Item 0 is one type of cell and is kept in the top left at all times. As you scroll, the cell is moved with you and kept in the top left corner.
Section 0, Item 1-n are the second type of cell and are kept at the top at all times.
Section 1-n, Item 0-n are the "stations", another type of cell, and are kept along the left border at all times.
All other cells are the "shows" and the fourth type of cell and are mapped to a specific x,y coordinate based on time and station.
This collectionView is very performant and has allowed us to give a great user experience for the most part. However, when completely loaded up with 10 days worth of data. It uses a decent amount of memory. ~100-150MB depending on the lineup, number of stations, and length of shows. Shorter shows means more cells mapped out to the collection view.
When the app is running with a large chunk of the guide data, sometimes, the collectionView will hiccup and my floating headers will stop moving. Then ALL of my cells will disappear. We have affectionately started calling this the White Screen of Death as the entire collection is rendered empty. At this time, the scroll bars are still visible and you can see yourself scrolling around, but no cells are loaded.
We've created the problem a few times with a device connected to Xcode's debugger and have some data. The data for populating all the cells is still available from debugger. cellForItemAtIndexPath
can be called from the debugger and returns a UICollectionViewCell. numberOfSections
and numberOfItemsInSections
still functions and shows correct numbers when printing from debugger. cellForItemAtIndexPath
function is never called after collection goes empty. Breakpoint in this method will never be hit. Layout is still accessible and variables can be accessed with no problems.
Now for the things that seem abnormal, but we don't know what to do with.
collectionView.contentSize
and collectionView.collectionViewLayout.contentSize
are different. On a non-broke device, they are the same when looking through the debugger.
collectionView.visibleCells
returns an empty array. This would technically be correct as our collection is in white screen of death mode... but we have sections and items in the sections, so not sure about that.
The problem is intermittent, but we can reproduce usually a few times an hour if we are trying hard enough. We think it's memory related, because it never happens on the simulator. Only on physical devices.
Since this is an unreleased app for a client, I've blacked out their navigational controls.
Has anyone seen a similar problem? Does anyone have any ideas for what to try next?
Last note, THANK YOU FOR READING THIS FAR! :)