我在实现NSWindowRestoration (在10.7Lion中)时遇到了一些困难。我没有收到协议通知。
有没有在某个地方实现此功能的示例应用?我在苹果开发者的网站上找不到。谢谢!
编辑:标记为答案的问题是有帮助的,但在我的例子中,问题是我使用的是一个仅限菜单的应用程序。我想窗口恢复还不适用于无坞应用程序。抓紧!
发布于 2012-12-01 02:34:07
"El Developer“描述的类方法+ (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler仅是解决方案的一半。
实现方法(并符合NSWindowRegistration协议)的类也必须注册为窗口的“恢复类”。在最初创建窗口时,使用- (void)setRestorationClass:(Class <NSWindowRestoration>)restorationClass方法注册它。
例如,对于窗口控制器,用于初始化:
_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);
}
}发布于 2012-02-08 04:05:33
有一个小代码片段:
+ (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler
{
// Get the window from the window controller,
// which is stored as an outlet by the delegate.
// Both the app delegate and window controller are
// created when the main nib file is loaded.
MyAppDelegate* appDelegate = (MyAppDelegate*)[[NSApplication sharedApplication] delegate];
NSWindow* mainWindow = [appDelegate.windowController window];
// Pass the window to the provided completion handler.
completionHandler(mainWindow, nil);
}找到了这里。
希望这能帮到你。
编辑:
一定要在应用程序类中实现协议,记住必须将它添加到m文件中。
@interface MyClass : FatherClass <NSWindowRestoration>
**我不是协议的100%的名字,所以最后一行可能是错的,对不起,我现在很着急,要么是那个,要么是NSWindowRestorationDelegate。
https://stackoverflow.com/questions/9187624
复制相似问题