我在实现 NSWindowRestoration
(在 10.7 Lion 中)时遇到了一些问题。我没有收到协议(protocol)通知。
是否有一个示例应用程序在某处实现了此功能?我在 Apple 开发者网站上找不到。谢谢!
<小时/>编辑:标记为答案的问题很有帮助,但我的情况的问题是我使用的是仅菜单栏的应用程序。我想窗口恢复还不适用于无坞应用程序。啪!
最佳答案
类方法+ (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler
正如“El Developer”所描述的那样,这只是解决方案的一半。
实现该方法(并符合 NSWindowRegistration 协议(protocol))的类也必须注册为窗口的“恢复类”。
最初创建窗口时,使用 - (void)setRestorationClass:(Class <NSWindowRestoration>)restorationClass
注册它。方法。
例如对于窗口 Controller ,用于初始化:
_myWindowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"];
_myWindowController.window.restorationClass = self.class;
_myWindowController.window.identifier = @"MyWindow";
恢复:
+ (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler {
if ([identifier isEqualToString:@"MyWindow"]) {
MyAppDelegate *appDelegate = (MyAppDelegate *)NSApplication.sharedApplication.delegate;
NSWindow *myWindow = appDelegate.myWindowController.window;
completionHandler(myWindow, nil);
}
}
关于objective-c - 有 NSWindowRestoration 的例子吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187624/