Hop*_*You 2 cocoa window class objective-c nswindowcontroller
我的一个类分配了一个自定义NSWindowController,我的类怎么知道窗口何时关闭?
CustomNSWindowController *wc = [[CustomNSWindowController alloc] init];
[wc showWindow:self];
//how to detect when window is closed?
Run Code Online (Sandbox Code Playgroud)
我正在尝试做的是让原始类(分配自定义窗口控制器的那个)知道窗口何时关闭,以便在不再需要窗口时我可以设置wc = nil :)
如果您的NSWindowController类被设置为窗口的委托,您只需响应该-windowWillClose:方法即可.
- (void)windowWillClose:(NSNotification *)notification
{
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
否则,由于这也是一个通知,您可以注册以接收来自任何课程的通知.
- (void)myWindowWillClose:(NSNotification *)notification
{
/* ... */
}
...
CustomNSWindowController *wc = ...;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(myWindowWillClose:)
name:NSWindowWillCloseNotification
object:[wc window]];
[wc showWindow:self];
Run Code Online (Sandbox Code Playgroud)
请参阅NSWindow类参考,NSWindowDelegate协议参考