I have a UICollectionView that I placed in a custom UIViewController via Storyboard and pinned its leading/trailing/top/bottom space to its superview.
Then I have a custom UICollectionViewController subclass that should use the collection view. So in the superview's UIViewController (PrimaryViewController) I have an outlet to the collection view and I instantiate my custom UICollectionViewController. I assign it the collection view and I assign the custom UICollectionViewController as delegate and dataSource for the collection view.
But when I run this, the collection view doesn't appear on the screen. It is obvious that the viewDidLoad() doesn't get called in the custom UICollectionViewController class so either I'm missing a key part or I'm approaching this the wrong way.
Can somebody tell me how to construct the connection between the collection view (which is placed via Storyboard) and the custom UICollectionViewController class (which is code only) in a way that makes this work properly?
Here's my (simplified) code so far ...
class PrimaryViewController : UIViewController {
@IBOutlet private weak var _collectionView:UICollectionView!
private var _collectionViewCtrl:CustomCollectionViewController!
override func viewDidLoad() {
super.viewDidLoad()
_collectionViewCtrl = CustomCollectionViewController(collectionView: _collectionView)
}
}
class CustomCollectionViewController : UICollectionViewController {
init(collectionView:UICollectionView) {
super.init(nibName: nil, bundle: nil)
self.collectionView = collectionView
self.collectionView.delegate = self
self.collectionView.dataSource = self
}
required init(coder aDecoder:NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
}
}

CustomCollectionViewControllerin thePrimaryViewControllerIB. You can add aUICollectionViewControllerto theUIViewControllerand then change it's class to your custom class. - thelaws