codez
codez

Reputation: 1532

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?

Upvotes: 6

Views: 4352

Answers (1)

Prontto
Prontto

Reputation: 1681

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

Upvotes: 6

Related Questions