Only my second time using UICollectionView\'s and perhaps I have bitten off more than I can chew but nevertheless:
I am implementing a UICollectionView (myCollection
In my case, what I had very stupidly forgotten to do was implement the UICollectionViewDataSource
protocol method numberOfItemsInSection
, so that is another thing to check.
Same happened to me. I had 2 UICollectionViews and I removed once since I didn't need that. After that I realised that the CellForItemAtIndexPath was not getting called but the other required methods. I tried all of the above but then I did the standard magic. Removed the collection view from storyboard and added again. Then it started working. Not sure why and I have no explanation but maybe some connection issues.
It can be realated layout problems. Check layout warnings from console, if exist.
If your class is subclass from UICollectionviewController and you are creating collectionView programmatically then use
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .Vertical
layout.itemSize = CGSizeMake(50, 50)
collectionView?.setCollectionViewLayout(layout, animated: false)
Also, make sure that reloadData is not called while collection view is updating with animation (insert, delete, update or performBatchUpdates).
If you're using collection view protocols you must connect the CollectionViewDataSource
and CollectionViewDelegate
protocols to your ViewController.