对通过鼠标单击或通过键盘调用的菜单项有何反应,例如: 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];
对通过鼠标单击或通过键盘调用的菜单项有何反应,例如: 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's -runModalForWindow:
,那么它将是整个应用程序的模态。因此,假设您没有调用它,那么在显示工作表时其他窗口和菜单命令应该可以正常工作。
但是,“退出”菜单项是一个例外。它不会让您退出,因为窗口有一个模态会话处于活动状态,它假定需要在应用程序退出之前处理它。如果这是您真正想要做的,那么一种可能的解决方案是子类化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];
}