I load a custom file import window in my Cocoa app using:
[NSApp runModalForWindow:window];
The window displays just fine, and is modal.
However, the application main menu is still active (e.g. File menu and items), which is making the modal display redundant.
I've googled this, searched stackoverflow and cocoa-dev, and searched the Apple docs, but can't find a way to turn the menu off, or at least selected men开发者_如何学Pythonu items.
Someone suggested using this:
NSModalSession session = [NSApp beginModalSessionForWindow:window];
[NSApp runModalSession];
but that doesn't seem to work either. Again, the window displays modally but the main menu is still active.
Can anyone suggest how I turn the main menu off (grey out menu items) when displaying a modal window please?
Is there a way to do this in one go at the menu-level, or do I need to turn off each individual menu item?
I must be missing the point somewhere, as this sort of menu behaviour is common in Cocoa apps.
Thanks
Darren.
I needed to implement (in the AppDelegate) the following method:
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
Returning NO disables the referenced menu item.
All works fine now.
精彩评论