Search code examples
iosuicollectionviewuipageviewcontroller

UICollectionView is nil


I have a UIViewController in storyboard which hosts a collectionView which is referenced using a IBOutlet. However, now I am placing this inside of a PageViewController and referencing it like this, rather than with the use of a seque :

let initial = FeedCollectionViewController()
let viewControllers = [initial]
setViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil)

The problem is that the collectionView is now nil.


Solution

  • Of course it's nil. You built your view controller in storyboard, so you should init it from storyboard. Like this:

    let tabSb = UIStoryboard(name: "Main", bundle: nil)
    let tabbarVc = tabSb.instantiateInitialViewController()