Next: 3.1.1 Action and Target Up: 3 Menus Previous: 3 Menus

3.1 Creating a Menu

An NSMenu object represents a menu. You create a new menu simply with:
NSMenu *menu;

menu = AUTORELEASE ([NSMenu new]);
This is an empty menu. To add items to it, you do as follows:
[menu addItemWithTitle: @"Quit" 
      action: @selector (terminate:)
      keyEquivalent: @"q"];
This adds to the menu menu an entry with title Quit (the title is the string which is displayed to the user). It's interesting to know that the method
actually returns a NSMenuItem object, which is the menu item object which was added to the menu. We don't need this return value in this example, so we discard it. Later on, we will need it.