任何NSWindowRestoration示例? [英] Any NSWindowRestoration examples?

查看:241
本文介绍了任何NSWindowRestoration示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行 NSWindowRestoration (在10.7 Lion中)时遇到了一些麻烦。我没有收到协议通知。

I'm having some trouble implementing NSWindowRestoration (in 10.7 Lion). I'm not getting the protocol notifications.

有一个在某处实现的示例应用程序吗?我在苹果开发者网站上找不到一个。谢谢!

Is there an example app with this implemented somewhere? I cannot find one on the Apple Developer site. Thanks!

编辑:标记为答案的问题是有帮助的,但我的情况下的问题是,菜单栏应用程序。我想窗口恢复不工作与坞站应用程序。 Snap!

The question marked as answer is helpful, but the problem in my case was that I was using a menubar-only application. I guess window restoration doesn't work with dockless apps yet. Snap!

推荐答案

类方法 +(void)restoreWindowWithIdentifier:(NSString *)identifier state: NSCoder *)状态completionHandler:(void(^)(NSWindow *,NSError *))completionHandler 描述的El Developer只是解决方案的一半。

The class method + (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler as described by "El Developer" is only half of the solution.

实现方法(并符合NSWindowRegistration协议)的类也必须注册为窗口的恢复类。
当窗口最初创建时,使用 - (void)setRestorationClass:(Class< NSWindowRestoration>)restorationClass 方法注册它。

The class that implements the method (and conforms to the NSWindowRegistration protocol) also has to be registered as the window's "Restoration Class". When the window is initially created, register it using the - (void)setRestorationClass:(Class <NSWindowRestoration>)restorationClass method.

例如。用于初始化:

_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);
    }
}

这篇关于任何NSWindowRestoration示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆