我正在尝试从按下NSMenuItem时启动的函数中打开NSViewController。
func settings (sender: NSStatusBarButton) {
//open NSViewController here?
}
答案 0 :(得分:2)
假设包含要打开的窗口的NSWindowController
具有故事板ID Settings
而NSViewController
具有自定义类SettingsController
,则禁用Visible At Launch
选项关联的窗口并使用此代码
var windowController : NSWindowController!
let mainStoryBoard = NSStoryboard(name: "Main", bundle: nil)
windowController = mainStoryBoard.instantiateController(withIdentifier: "Settings") as! NSWindowController
let settingsController = windowController.window!.contentViewController as! SettingsController
// make initial settings before showing the window
windowController.showWindow(self)