I recently noticed that my UICollectionView displays correctly running in iOS8.3, but not on iOS 9.1
I put a breakpoint in the dataSource protocol's numberOfItemsInSection: method, and I observe:
- when the app initially loads it returns 0, as I have not yet loaded the model objects that back the cells in the collection view
- once the objects have been loaded, the app calls [self.collectionView reloadData]
- this triggers another call getting made to numberOfItemsInSection: which now returns the non-zero value corresponding to the number of model objects
At this point, I would expect to see cellForItemAtIndexPath getting called, however it is never called.
BUT, when I changed the numberOfItemsInSection: method to always return a hard coded value (3) the 3 cells display correctly (cellForItemAtIndexPath gets called as expected.)
so my current hypotheses are:
1. returning 0 for numberOfItemsInSection at the initial load somehow puts the collectionView in a state where the contentView has at least one dimension set to zero.
2. reloadData is not enough to 'wake up' the collection view to realize that the contentSize needs to increase.
again, this works fine with iOS 8.3
it also works on 9.1 if numberOfItemsInSection returns a hard coded non-zero value everytime it is called.
my problem only occurs in 9.1 and when numberOfItemsInSection returns 0 the first time it is called, and then returns a non-zero value the second time it is called.
not sure if this makes a difference, but my UICollectionView is in a .xib, (not in a storyboard)
thanks in advance for any guidance,