I'm an XCode newbie and I'm trying to achieve what follows with an iOS8 app:
- create a Tabbed Application
with a single initial tab that contains a text field and a button to:
- create a new CollectionView
- and add a new tab item to reach it
- be able to repeat the creation n times
Steps 1 and 2 are pretty easy. I'm stucked @ point 3. Now in my project I have:
- MyCollectionViewController which is a default UICollectionViewController where I've changed numberOfSectionsInCollectionView to return 1 section and numberOfItemsInSection to get 3 cells (the reuseIdentifier is set to "MyCell")
FirstViewController.swift with:
- an IBOutlet to a UITextField (newTabItemName) to get the title to use for the new TabItem
the following IBAction for the UIButton:
@IBAction func generateNewTabItem(sender: UIButton) { let vc: MyCollectionViewController = MyCollectionViewController() vc.title = newTabItemName.text self.tabBarController?.viewControllers?.append(vc) }
If I run the app I see the initial view with the text field and the button; if I change the text and click the button I get the TabItem. I can also do that n times as I wanted. The problem is that if I click one of the new tabs I get the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
I think I'm not that far from what I need but I don't know what's missing.
Any suggestion?
Thanks.
Bye...