Next: Action and Target Up: Menus Previous: Menus

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
  
addItemWithTitle:action:keyEquivalent:
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.



Subsections

Nicola Pero 2000-07-21