-
01-10-2019 - |
题
一个人如何反应通过鼠标单击或通过键盘调用的菜单,例如:cmd+q?
[NSApp beginSheet:my_sheet ...arguments... ];
/*
The sheet is now shown and the mainmenu isn't usable.
How does one make it usable?
*/
[NSApp endSheet:my_sheet returnCode:0];
解决方案
我认为您正在使用NSAPP -beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:
方法。如果是这样,那么您已经应该能够执行菜单命令。该方法仅针对给定窗口运行表模式(与整个应用程序的模态相反)。但是,如果您也致电NSAPP -runModalForWindow:
, ,那么它将是整个应用程序的模态。因此,假设您没有打电话,则在显示工作表时,其他Windows和菜单命令应正常工作。
但是,“退出”菜单项是一个例外。它不会让您退出,因为有一个模态会话为一个窗口活动,在应用程序可以退出之前,它假定需要处理它。如果这是您真正想做的,那么一种可能的解决方案是子类 NSApplication
并覆盖它 -terminate:
首先关闭工作表的方法(如果打开)。首先,您需要做一个子类 NSApplication
, ,并让您的应用程序通过在“ mainmenu.xib”中设置它,并将其用于 Principal Class
在您的“ info.plist”中)。然后将类似的东西添加到您的子类中:
- (void)terminate:(id)sender
{
// First close the sheet (if it's active), using whatever method
// you have set up to do this...
[((MyAppDelegate*)[self delegate]) closeSheet:self];
// Now call the normal implementation
[super terminate:sender];
}
不隶属于 StackOverflow