【问题标题】:How do you re-open a closed window created in the storyboard in OS X如何重新打开在 OS X 的故事板中创建的关闭窗口
【发布时间】:2015-06-02 11:59:36
【问题描述】:
【问题讨论】:
标签:
macos
swift
xcode-storyboard
【解决方案1】:
这很容易存档,即使它不是一个优雅的解决方案。为您的主窗口控制器向您的应用程序委托添加一个新属性。在以下示例中,我将控制器称为MainWindowController。
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var mainWindowController: MainWindowController? = nil
func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
mainWindowController?.window?.makeKeyAndOrderFront(self)
return false
}
}
在主窗口控制器的初始化中,我在应用委托中注册了控制器:
class MainWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
// ...initialisation...
// Register the controller in the app delegate
let appDelegate = NSApp.delegate as! AppDelegate
appDelegate.mainWindowController = self
}
}
就是这样,非常适合我。