如何关闭窗口(卸载 NIB)?
我有一个自定义的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢@彼得·霍西。
打开文件的笔尖。在窗口上,您需要将窗口的“引用出口”连接到“文件所有者”,然后选择“窗口”。否则什么都行不通。
Thanks @peter hosey.
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.
你不用卸下笔尖; “加载”它只是取消归档其中归档的对象。这并不是一种无限期持续的状态;而是一种状态。这是一个瞬间的动作。一旦您取消归档该对象,它来自哪里就不再重要了。
如果您不在窗口控制器中,那么:
关闭
消息。close
消息或向其发送release
之前,打开releasedWhenClosed
属性(您可以在 IB 中执行此操作)close
消息之后的消息。但由于您位于窗口控制器中,只需 给自己发送一个 <代码>关闭消息。
另请参阅 基于文档的应用程序概述中的“窗口关闭行为”(基于文档的应用程序是窗口控制器的主要用户)。
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:
close
message.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).