erichoracek / MSCollectionViewCalendarLayout

UICollectionViewLayout for displaying cells chronologically. Similar to the iOS Calendar app.
MIT License
1.95k stars 271 forks source link

Crash on reloading data and no data available #7

Closed ogezue closed 11 years ago

ogezue commented 11 years ago

When I first have data loaded and displayed and then fetch new data from server and then 0 items have to be displayed the app crashes with that output

Assertion failure in -[UICollectionViewData layoutAttributesForDecorationViewOfKind:atIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UICollectionViewData.m:639 2013-04-04 09:32:43.214 MyApp[84604:c07] *\ Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for layout attributes for decoration view of kind MSCollectionElementKindDayColumnHeaderBackground in section 0 when there are only 0 sections in the collection view'

This is how I reload the data: -(void) loadDataFromServer:(BOOL) fromServer{ self.events = [[DataSourceManager sharedInstance] loadAllEventsFromServer:fromServer];

[self.collectionView reloadData];

}

self.events is an Array of Sections. I exchanged NSFetchedResultsController. And it is working if there is no data from the beginning or data with several items.

ogezue commented 11 years ago

Solved it by calling

 [self.collectionViewLayout invalidateLayoutCache];

before reloading data.