如何关闭窗口(卸载NIB)? [英] How to close a window (unload a NIB)?
问题描述
我有一个自定义 NSWindowController
子类,在初始化期间加载NIB文件,如下所示:
I have a custom NSWindowController
subclass that loads a NIB file during initialization like this:
self = [super initWithNibNamed:@"myNib"];
if (self != nil) {
[self window];
}
nib包含一些自定义视图和一些其他控件。 NSWindowController
是文件的所有者,至少有一个视图甚至绑定到它。
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.
推荐答案
你不能卸载一个笔尖; 加载它只是将存档在其中的对象归档。这不是一个无限期持续的状态;这是一个短暂的行动。一旦你取消了对象的存档,那么它来自何处。
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:
- 要关闭窗口,您需要发送
关闭
>。 - 要关闭和释放窗口,您需要具有其
releasedWhenClosed
属性打开(您可以在IB中执行此操作),然后再发送关闭
消息,或向其发送关闭
消息后显示 消息。
- To close a window, you would send it a
close
message. - To close and release a window, you would need to either have its
releasedWhenClosed
property turned on (you can do this in IB) before you send it aclose
message, or send it arelease
message after theclose
message.
窗口控制器,只需向您自己发送关闭
讯息。
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).
这篇关于如何关闭窗口(卸载NIB)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!