search by tags

for the user

adventures into the land of the command line

how to use multiple storyboards with xcode 7 and swift 2

To use multiple storyboards in you xcode project follow these steps:

Right click on your project folder and choose to add a new file.

image

Select Storyboard from the appropriate User Interface submenu.

image

Name your storyboard, you can move them around into subfolders for better organisation if you want.

image

In your first storyboard, add a View Controller. On the right side of the screen under the Attribute Inspector tab, check the box named “Is Initial View Controller” is ticked and the view itself has an arrow pointing to it like in the image below.

image

Then on the Identity Inspector tab, give the Initial View Controller a Storyboard ID. This can be whatever you want, but make it identifiable and unique.

image

Do the same steps with your other storyboard.

image

Don’t forget to give the View Controller a Storyboard ID.

image

You can even give a Non-Initial View Controller a Storyboard ID, if you want to jump to other views in the same Storyboard.

image

Add code like below to the .swift files in places where you want transitions to other Views to happen.

Jump to the Transactions Storyboard, to the View Controller named BooksView

let storyboard = UIStoryboard(name: "Transactions", bundle: nil)
let transactionsView = storyboard.instantiateViewControllerWithIdentifier("BooksView") as! SWRevealViewController
self.presentViewController(transactionsView, animated: true, completion: nil)

Jump to the Transactions Storyboard, to the View Controller named TargetsView

let storyboard = UIStoryboard(name: "Transactions", bundle: nil)
let settingsView = storyboard.instantiateViewControllerWithIdentifier("TargetsView") as! TargetsViewController
self.revealViewController().pushFrontViewController(settingsView, animated: true)

Jump to the Graphs Storyboard, to the View Controller named GraphsView

let storyboard = UIStoryboard(name: "Graphs", bundle: nil)
let settingsView = storyboard.instantiateViewControllerWithIdentifier("GraphsView") as! GraphsViewController
self.revealViewController().pushFrontViewController(settingsView, animated: true)

You can add as many as you want!