Reputation: 229
I'm trying to add a custom UICollectionViewController
in a child UIView
and it crashes my app. Is there something wrong with my code or how my CustomCollectionViewController
is implemented?
@IBOutlet weak var childView: UIView!
let myCollectionView = CustomCollectionViewController()
//inside viewDidLoad
self.addChildViewController(self.myCollectionView)
self.myCollectionView.didMoveToParentViewController(self)
self.myCollectionView.view.frame = self.childView.bounds<--crashes after executing this line
self.childView.addSubview(self.myCollectionView.view)
self.myCollectionView.delegate = self
Upvotes: 1
Views: 195
Reputation: 21
This may be a little late, but initialize your CollectionViewController
with a layout parameter.
Instead of:
let myCollectionView = CustomCollectionViewController()
use:
let myCollectionView = CustomCollectionViewController.init(collectionViewLayout: UICollectionViewFlowLayout())
That worked for me.
Upvotes: 2