Menus
The
NSMenu
and
NSMenuItem
classes implement menus in Cocoa.
NSMenu provides an implementation for actual
menus, while NSMenuItem represents individual
items within menus. An application’s menus appear in
the main menu bar across the top of the screen. By and large, an
application’s main menu is assembled in Interface
Builder, which provides facilities for editing menu structures and
setting menu item targets and actions. Additionally, Interface
Builder has several pre-configured menus, such as File and Edit that
contain standard menu items familiar to users. An
application’s main menu is contained in the main nib
of an application.
Every application also has a Dock menu, which pops up when you
right-click on an application’s Dock icon. Dock
menus are easily created in Interface Builder by connecting an
instance of NSMenu to the File’s
Owner’s dockMenu outlet.
Alternatively, the application delegate can supply a Dock menu by
implementing the method applicationDockMenu: (this
is useful if you want to dynamically reconfigure the menu). A third
way of specifying a Dock menu is to assemble the
NSMenu object in a nib and specify the
nib’s file name in the
application’s
Info.plist
file under the
AppleDockMenu key.
NSView objects manage
contextual menus. In Interface Builder,
every view has a menu outlet, which can be
connected to an NSMenu object. The menu that you connect to this outlet will appear as a contextual menu when you right-click over the view. Contextual menus can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access