step1. I new a project in Xcode 13.2.1 with macOS App, swift and storyboard
step2. The default NSViewController named InitialViewController. I add a button named open.
step3. I add a NSViewController named NewViewController and storyboard ID is NewView.
step4. I connected the button action and add the code shown below to show NewViewController with no modal.
@IBAction func click(_ sender: Any) {
let newView = (self.storyboard!.instantiateController(withIdentifier: "NewView") as! NewViewController)
let windowVC = NSWindowController(window: newView.view.window)
windowVC.showWindow(nil)
}
step5. I run the App and click the button, and then I found that the NewViewController didn't show.
How do I show a new/additional NSViewController with no modal? Could you provide a sample code? Thanks in advance.
If the
NSViewControllerdoesn't have a parentNSWindowControllerin Interface Builder there is nowindowand you have to create one either in IB or in code.For example in code add in
AppDelgateAnd change the IBAction to