Reputation: 2704
In my app I have an UICollectionView
and a UITableView
. I use the TV for navigation and the CV for detail-presentation. The widths of the TV & the CV can be changed by the user (per panning; like a flexible UISplitViewController
).
When the user selects an item in the TV, the app updates die CV with the corresponding detail-items. I use
[myCV reloadData];
for updating the CV. This works very well, when the CV is visible.
The User is allowed to zoom the navigation-TV to maximum (full screen width) - for that I set the CV-width to zero. When the CV ist not visible, the user selects another items (-> cv reloadData) and when then the user re-opens the content-CV, the following error occurs:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items before section 2 when there are only 1 sections in the collection view'
As I could figure out so far - the CV does not proper update itself while reloadData, when it is not visible (because its width is zero, or it is offscreen, or is hidden by another view). When I set the CVs width again to a value > 0, the error occurs. It seems that the CV handle still the old cellItems instead of the new cellItems provided by the dataDelegate.
Any idea how I can fix this situation?
Upvotes: 3
Views: 1323
Reputation: 2704
I solved the situation with a work-around.
Before I set the content-view to a zero-width, I remove the content-view from its superview. And I do NOT set the content-view width to 0. When the user slides the content-view open again, and I should set a width > 0, I add the view again to its superview and set THEN the new width to its frame.
It is not very elegant, but works like charme.
Upvotes: 2