My app has a UIViewController class; inside this class I connect a UICollectionView loaded from a Storyboard.
I'm creating a custom layout with the UICollectionViewLayout class. Here's what it looks like:
class MyLayout: UICollectionViewLayout {
override func prepareLayout() {
super.prepareLayout()
}
override func collectionViewContentSize() -> CGSize {
let attributes = super.collectionViewContentSize()
return attributes
}
override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
let attributes = super.layoutAttributesForElementsInRect(rect) as? [UICollectionViewLayoutAttributes]
return attributes
}
override func layoutAttributesForItemAtIndexPath(indexPath:
NSIndexPath) -> UICollectionViewLayoutAttributes {
let attributes = super.layoutAttributesForItemAtIndexPath(indexPath)
return attributes
}
}
To assign a UICollectionViewLayout to the UICollectionView, I use the collectionViewLayout property of the UICollectionView:
myCollectionView.collectionViewLayout = MyLayout()
Running the app, the UICollectionViewCells are no longer visible. Though, they were visible before assigning the UICollectionViewLayout. I can now only see the background of the UICollectionView.
Why are cells no longer visibile?
Update
I looked carefully at the UICollectionViewLayoutAttributes of my UICollectionView, particularly the contentSize. I printed out its value and it seems to be equal to (0.0, 0.0). The attributes value for layoutAttributesForElementsInRect is also equal to nil. Definitely a red flag.