【发布时间】:2014-06-10 00:50:12
【问题描述】:
我尝试在非基于文档的应用程序中在 Swift 中实现 NSWindowRestoration 协议。然而,restoreWindowWithIdentifier 方法永远不会在应用程序启动时被调用。谁能指出我的错误?
这是代码的子集(编译和运行良好):
class AppDelegate: NSObject, NSApplicationDelegate, NSWindowRestoration {
var windowController : MyWindowController?
func applicationDidFinishLaunching(aNotification: NSNotification?) {
windowController = MyWindowController(windowNibName:"ImageSequenceView")
}
class func restoreWindowWithIdentifier(identifier: String!, state: NSCoder!, completionHandler: ((NSWindow!,NSError!) -> Void)!) {
NSLog("restoreWindowWithIdentifier: \(identifier), state: \(state)")
}
}
class MyWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad();
window.restorationClass = AppDelegate.self
}
}
提前致谢!
【问题讨论】:
-
出于好奇,当您交换
super.windowDidLoad()的顺序并设置window.restorationClass时会发生什么。 -
抱歉,长途旅行。刚试过,但没有任何作用......
-
当我使用
self.dynamicType并确保我的系统首选项设置为恢复 WindowsrestoreWindowWithIdentifier时,我的班级被调用。
标签: cocoa swift state-restoration