UICollectionView reloadData not functioning properly in iOS 7

VaporwareWolf picture VaporwareWolf · Sep 14, 2013 · Viewed 73.9k times · Source

I've been updating my apps to run on iOS 7 which is going smoothly for the most part. I have noticed in more than one app that the reloadData method of a UICollectionViewController isn't acting quite how it used to.

I'll load the UICollectionViewController, populate the UICollectionView with some data as normal. This works great on the first time. However if I request new data (populate the UICollectionViewDataSource), and then call reloadData, it will query the data source for numberOfItemsInSection and numberOfSectionsInCollectionView, but it doesn't seem to call cellForItemAtIndexPath the proper number of times.

If I change the code to only reload one section, then it will function properly. This is no problem for me to change these, but I don't think I should have to. reloadData should reload all visible cells according to the documentation.

Has anyone else seen this?

Answer

Shaunti Fondrisi picture Shaunti Fondrisi · Dec 4, 2013

Force this on the main thread:

dispatch_async(dispatch_get_main_queue(), ^ {
    [self.collectionView reloadData];
});