Question

I have a cocoa app with two types windows each of which requires a different main menu to be displayed.

In my MainMenu.xib I have the default MainMenu. In Window1.xib I have Window1 and in Window2.xib I have Window2 and it's MainMenu.

When I have the first Window open I have the default Menu, when I open Window2 I get it's menu.

However, when I switch back to Window1 I still see Window2's menu. How do I make the menu that is displayed follow the key window?

Was it helpful?

Solution

NSApplication has a method, - (void)setMainMenu:(NSMenu *)aMenu. You can pass it a reference to the correct menu in the appropriate window controller, by implementing - (void)windowDidBecomeKey:(NSNotification *)notification.

Keep in mind it may be easier to change just the submenus instead of swapping out the entire main menu, since you won't have to maintain two different copies of the application, help, and other menus that won't change between the two windows.

OTHER TIPS

Generally, you shouldn't replace the entire main menu every time. It's more compliant with the Human Interface Guidelines to simply disable any menu items that don't apply to the current window. And if you really should have a completely different set of menus in the menu bar, maybe you should split that part of your application into a separate application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top