如何关闭窗口(卸载 NIB)?

发布于 2024-08-29 05:42:02 字数 312 浏览 4 评论 0原文

我有一个自定义的 NSWindowController 子类,它在初始化期间加载 NIB 文件,如下所示:

self = [super initWithNibNamed:@"myNib"];
if (self != nil) {
    [self window];
}

nib 包含一些自定义视图和一些其他控件。 NSWindowController 是文件的所有者,并且至少有一个视图与其绑定。

简而言之,我需要做什么才能关闭并释放该窗口?我花了一整天的时间试图弄清楚这一点,但我仍然一无所知。

I have a custom NSWindowController subclass that loads a NIB file during initialization like this:

self = [super initWithNibNamed:@"myNib"];
if (self != nil) {
    [self window];
}

The nib contains some custom views and some other controls. The NSWindowController is the file's owner and at least one of the views even binds to it.

Simply, what do I have to do to close and release that window? I spend the whole day trying to figure that out and I am still clueless.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哀由 2024-09-05 05:42:02

谢谢@彼得·霍西。

[self close]; // will work only if your nib is wired up correctly.

打开文件的笔尖。在窗口上,您需要将窗口的“引用出口”连接到“文件所有者”,然后选择“窗口”。否则什么都行不通。

Thanks @peter hosey.

[self close]; // will work only if your nib is wired up correctly.

Open the nib for your file. On the Window you need to wire the "Referencing Outlet" of the window to the "Files Owner" and choose Window. Otherwise nothing will work.

-柠檬树下少年和吉他 2024-09-05 05:42:02

你不用卸下笔尖; “加载”它只是取消归档其中归档的对象。这并不是一种无限期持续的状态;而是一种状态。这是一个瞬间的动作。一旦您取消归档该对象,它来自哪里就不再重要了。

如果您不在窗口控制器中,那么:

但由于您位于窗口控制器中,只需 给自己发送一个 <代码>关闭消息

另请参阅 基于文档的应用程序概述中的“窗口关闭行为”(基于文档的应用程序是窗口控制器的主要用户)。

You don't unload a nib; “loading” it is simply unarchiving the objects that are archived within it. That's not a state that persists indefinitely; it's a momentary action. Once you've unarchived the object, it doesn't matter where it came from.

If you were not in a window controller, then:

But since you are in a window controller, just send yourself a close message.

See also “Window Closing Behavior” in the Document-Based Applications Overview (document-based apps being the main users of window controllers).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文