Initializing another window using storyboard for OS X

前端 未结 4 1634
春和景丽
春和景丽 2021-02-02 09:46

I have created a Cocoa application in Xcode6 which uses storyboards. As a template, Xcode provides a window for the application. I want to add a second window to show when the p

4条回答
  •  臣服心动
    2021-02-02 10:09

    Swift 5:

    The project setup in XCode 13 has entirely changed. There is no longer an example of how to connect to the storyboard from the AppDelegate. Instead, they are hardcoding a NSWindow. I still find Storyboards useful, hence the below should come in handy. Remember to name your WindowController in Storyboard as mainWindowController.

    let mainStoryboard = NSStoryboard.init(name: NSStoryboard.Name("Main"), bundle: nil)
    var monitorcontroler = mainStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("mainWindowController")) as! NSWindowController
    monitorcontroler.showWindow(self)
    

提交回复
热议问题