【发布时间】:2012-12-04 03:28:19
【问题描述】:
我想在用户单击 NSWindowController 中的红色关闭按钮时停止模式。
在 NSWindowController 中,有“确定”和“取消”按钮。
- (IBAction)okButtonClicked:(id)sender
{
[NSApp stopModalWithCode:NSOKButton];
[self.window close];
}
- (IBAction)cancelButtonClicked:(id)sender
{
[NSApp stopModalWithCode:NSCancelButton];
[self.window close];
}
当我单击红色关闭按钮时,窗口将关闭,并且模式不会停止。 我找到了 windowWillClose: 函数。
- (void)windowWillClose:(NSNotification *)notification
{
if ([NSApp modalWindow] == self.window)
[NSApp stopModal];
}
然而,
if ([NSApp runModalForWindow:myWindowController.window] != NSOKButton)
return;
即使我点击 OK 按钮,windowWillClose: 函数也会被调用并且 runModalForWindow: 函数总是返回 NSCancelButton。
我可以将成员变量添加到 myWindowController 作为模态的结果。
但我认为会有另一种通用的方法来解决这个问题。
我想采取一种简单的方法。
【问题讨论】:
标签: objective-c macos modal-dialog nswindowcontroller nspanel