Reputation: 373
I am in the process of building an iOS app using Swift and have been advised to use a storyboard for each feature as each feature will have about 10 views. Starting from the main storyboard, could anyone provide advice on how to transition between storyboards using Swift? Alternatively, is there something better to do than using multiple storyboards if I want to avoid the confusion of a 50+ view main storyboard?
Here is what ended up working:
let secondVC:UIViewController = UIStoryboard(name: "SecondStoryboard", bundle:nil).instantiateViewControllerWithIdentifier("numberTwo") as UIViewController
@IBAction func changeStoryBoardButtonClicked(sender: AnyObject) {
presentViewController(secondVC, animated: false, completion: nil)
}
Upvotes: 2
Views: 6092
Reputation: 104082
When your app needs to move to a new controller that's in a different storyboard, you have to instantiate the new storyboard, then instantiate the initial view controller there.
let sb = UIStoryboard(name: "SomeStoryboardName", bundle: nil)
let vc2 = sb.instantiateInitialViewController() as UIViewController // or whatever the class is of that initial vc
Upvotes: 3