Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a multi-page application using Swift for OS X?

I've created an OS X Cocoa Application using the Swift language in Xcode. I have setup my main storyboard like this:

Main Storyboard

And when I run the application and hit the button, it opens a new window for the other View Controller like this which is not what I want. This is what I get:

Display

What I want exactly is that the ViewControllers to switch but in the same window, and not in a new window. How do I stop the new window behaviour and make this work in the same window?

like image 871
Hassan Althaf Avatar asked Aug 17 '15 10:08

Hassan Althaf


People also ask

How do I make multiple storyboards in Xcode?

1. Create storyboards by File -> New -> File -> Select Storyboard -> Next -> Give it a name -> Create.


1 Answers

In your ViewController where your button action is:

@IBAction func changeView(sender: AnyObject) {
    let secondVC = storyboard?.instantiateControllerWithIdentifier("SecondVC") as? SecondViewController
    view.window?.contentViewController = secondVC
}

And remember to identify your second viewcontroller like this enter image description here

like image 87
Prontto Avatar answered Oct 31 '22 19:10

Prontto