swiftmacosviewsegue

How do you segue in a mac application without creating a new window?


I'm trying to segue to the bottom view controller after hitting the submit button, but when I do it creates a new window.

Storyboard


Solution

  • That is one of the default behaviour of Cocoa segues. One solution is to close the previous window when moving through the segue.

    override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
        self.view.window?.close()
        //Pass data to new view
    }
    

    I have just found this tutorial and the developer creates a very interesting transition effect, take a look at the source code at the bottom of the page