< Previous PageNext Page > Hide TOC

Removing a Menu

To remove a menu item from a menu, you send removeItem: or removeItemAtIndex: to the NSMenu object managing the menu item.

To remove an entire menu from the menu bar, you use the same technique. The menus in the menu bar are themselves items of another menu: the root menu, or main menu. To get the main menu, send mainMenu to NSApp, the global application instance. Then send removeItem: to the main menu; or find the index of the menu to be removed and send removeItemAtIndex: to the main menu. Listing 1 illustrates the latter procedure.

Listing 1  Removing a menu from the menu bar

- (IBAction)removeMenu:(id)sender {
    NSMenu* rootMenu = [NSApp mainMenu];
    // sender is an NSMenuItem
    [rootMenu removeItemAtIndex:[rootMenu indexOfItemWithSubmenu:[sender menu]]];
}


< Previous PageNext Page > Hide TOC


© 2001, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-06-26)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.