NSMenu Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSMenu.h
Related sample code

Overview

The NSMenu class defines an object that manages an application’s menus.

Tasks

Managing the Menu Bar

Creating an NSMenu Object

Adding and Removing Menu Items

Finding Menu Items

Finding Indices of Menu Items

Managing Submenus

Enabling and Disabling Menu Items

Getting and Setting the Menu Font

Handling Keyboard Equivalents

Simulating Mouse Clicks

Managing the Title

Configuring Menu Size

Getting Menu Properties

Managing Menu Change Notifications

Displaying Contextual Menus

Displaying Context-Sensitive Help

Managing Display of the State Column

Controlling Allocation Zones

Handling Highlighting

Managing the Delegate

Handling Tracking

Deprecated Methods

Class Methods

menuBarVisible

Returns a Boolean value that indicates whether the menu bar is visible.

+ (BOOL)menuBarVisible
Return Value

YES if the menu bar is visible, otherwise NO.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSMenu.h

menuZone

Returns the zone from which NSMenu objects should be allocated.

+ (NSZone *)menuZone
Return Value

The zone from which NSMenu objects should be allocated.

Special Considerations

This is left in for compatibility and always returns NSDefaultMallocZone. It is not necessary to use this.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

popUpContextMenu:withEvent:forView:

Displays a contextual menu over a view for an event.

+ (void)popUpContextMenu:(NSMenu *)menu withEvent:(NSEvent *)event forView:(NSView *)view
Parameters
menu

The menu object to use for the contextual menu.

event

An NSEvent object representing the event.

view

The view object over which to display the contextual menu.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSMenu.h

popUpContextMenu:withEvent:forView:withFont:

Displays a contextual menu over a view for an event using a specified font.

+ (void)popUpContextMenu:(NSMenu *)menu withEvent:(NSEvent *)event forView:(NSView *)view withFont:(NSFont *)font
Parameters
menu

The menu object to use for the contextual menu.

event

An NSEvent object representing the event.

view

The view object over which to display the contextual menu.

font

An NSFont object representing the font for the contextual menu. If you pass in nil for the font, the method uses the default font for menu.

Discussion

Specifying a font using the font parameter is discouraged. Instead set the menu’s font using the setFont: method and pass nil for the font parameter.

Availability
  • Available in OS X v10.3 and later.
Declared In
NSMenu.h

setMenuBarVisible:

Sets whether the menu bar is visible and selectable by the user.

+ (void)setMenuBarVisible:(BOOL)visible
Parameters
visible

YES if menu bar is to be visible, otherwise NO.

Availability
  • Available in OS X v10.2 and later.
Declared In
NSMenu.h

Instance Methods

addItem:

Adds a menu item to the end of the receiver.

- (void)addItem:(NSMenuItem *)newItem
Parameters
newItem

The menu item (an object conforming to the NSMenuItem protocol) to add to the menu.

Discussion

This method invokes insertItem:atIndex:. Thus, the receiver does not accept the menu item if it already belongs to another menu. After adding the menu item, the receiver updates itself.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

addItemWithTitle:action:keyEquivalent:

Creates a new menu item and adds it to the end of the receiver.

- (NSMenuItem *)addItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv
Parameters
aString

A string to be made the title of the menu item.

aSelector

The action-message selector to assign to the menu item.

keyEquiv

A string identifying the key to use as a key equivalent for the menu item. If you do not want the menu item to have a key equivalent, keyEquiv should be an empty string (@"") and not nil.

Return Value

The created menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be created.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSMenu.h

allowsContextMenuPlugIns

Returns whether the popup menu allows appending of contextual menu plugin items.

- (BOOL)allowsContextMenuPlugIns
Return Value

YES if the popup menu allows appending of contextual menu plugin items, otherwise NO.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

autoenablesItems

Returns a Boolean value that indicates whether the receiver automatically enables and disables its menu items.

- (BOOL)autoenablesItems
Return Value

YES if the receiver automatically enables and disables its menu items (based on the NSMenuValidation informal protocol), otherwise NO.

Discussion

By default, NSMenu objects autoenable their menu items. See the protocol specification for more information.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

cancelTracking

Dismisses the menu and ends all menu tracking.

- (void)cancelTracking
Availability
  • Available in OS X v10.5 and later.
Declared In
NSMenu.h

cancelTrackingWithoutAnimation

Dismisses the menu and ends all menu tracking without displaying the associated animation.

- (void)cancelTrackingWithoutAnimation
Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

delegate

Returns the receiver’s delegate.

- (id < NSMenuDelegate >)delegate
Return Value

The receiver’s delegate.

Availability
  • Available in OS X v10.3 and later.
Declared In
NSMenu.h

font

Returns the font used to display the menu and its submenus.

- (NSFont *)font
Return Value

The font object used for displaying the menu.

Availability
  • Available in OS X v10.6 and later.
See Also
Declared In
NSMenu.h

helpRequested:

Overridden by subclasses to implement specialized context-sensitive help behavior.

- (void)helpRequested:(NSEvent *)event
Parameters
event

An NSEvent object representing the event associated with the help request.

Discussion

Subclasses in their implementation of this method should cause the Help Manager (NSHelpManager) to display the help associated with the receiver. Never invoke this method directly.

Special Considerations

On OS X v10.6 and later this method has no effect. This method may be deprecated in a future release.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

highlightedItem

Returns the highlighted item in the receiver.

- (NSMenuItem *)highlightedItem
Return Value

Returns the highlighted item in the receiver, or nil if no item in the menu is highlighted.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMenu.h

indexOfItem:

Returns the index identifying the location of a specified menu item in the receiver.

- (NSInteger)indexOfItem:(NSMenuItem *)anObject
Parameters
anObject

A menu item—that is an object conforming to the NSMenuItem protocol.

Return Value

The integer index of the menu item or, if no such menu item is in the menu, –1.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

indexOfItemWithRepresentedObject:

Returns the index of the first menu item in the receiver that has a given represented object.

- (NSInteger)indexOfItemWithRepresentedObject:(id)anObject
Parameters
anObject

A represented object of the receiver.

Return Value

The integer index of the menu item or, if no such menu item is in the menu, –1.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

indexOfItemWithSubmenu:

Returns the index of the menu item in the receiver with the given submenu.

- (NSInteger)indexOfItemWithSubmenu:(NSMenu *)anObject
Parameters
anObject

A menu object that is a menu item of the receiver (that is, a submenu).

Return Value

The integer index of the menu item or, if no such menu item is in the menu, –1.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

indexOfItemWithTag:

Returns the index of the first menu item in the receiver identified by a tag.

- (NSInteger)indexOfItemWithTag:(NSInteger)aTag
Parameters
aTag

An integer tag associated with the menu item of the receiver.

Return Value

The integer index of the menu item or, if no such menu item is in the menu, –1.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

indexOfItemWithTarget:andAction:

Returns the index of the first menu item in the receiver that has a specified action and target.

- (NSInteger)indexOfItemWithTarget:(id)anObject andAction:(SEL)actionSelector
Parameters
anObject

An object that is set as the target of a menu item of the receiver.

actionSelector

A selector identifying an action method. If actionSelector is NULL, the first menu item in the receiver that has target anObject is returned

Return Value

The integer index of the menu item or, if no such menu item is in the menu, –1.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

indexOfItemWithTitle:

Returns the index of the first menu item in the receiver that has a specified title.

- (NSInteger)indexOfItemWithTitle:(NSString *)aTitle
Parameters
aTitle

The title of a menu item in the receiver.

Return Value

The integer index of the menu item or, if no such menu item is in the menu, –1.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

initWithTitle:

Initializes and returns a menu having the specified title and with autoenabling of menu items turned on.

- (id)initWithTitle:(NSString *)aTitle
Parameters
aTitle

The title to assign to the receiver.

Return Value

The initialized NSMenu object or nil if the object could not be initialized.

Special Considerations

This method is the designated initializer for the class.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

insertItem:atIndex:

Inserts a menu item into the receiver at a specific location.

- (void)insertItem:(NSMenuItem *)newItem atIndex:(NSInteger)index
Parameters
newItem

An object conforming to the NSMenuItem protocol that represents a menu item.

index

An integer index identifying the location of the menu item in the menu.

Discussion

This method posts an NSMenuDidAddItemNotification, allowing interested observers to update as appropriate. This method is a primitive method. All item-addition methods end up calling this method, so this is where you should implement custom behavior on adding new items to a menu in a custom subclass. If the menu item already exists in another menu, it is not inserted and the method raises an exception of type NSInternalInconsistencyException.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

insertItemWithTitle:action:keyEquivalent:atIndex:

Creates and adds a menu item at a specified location in the receiver.

- (NSMenuItem *)insertItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv atIndex:(NSInteger)index
Parameters
aString

A string to be made the title of the menu item.

aSelector

The action-message selector to assign to the menu item.

keyEquiv

A string identifying the key to use as a key equivalent for the menu item. If you do not want the menu item to have a key equivalent, keyEquiv should be an empty string (@"") and not nil.

index

An integer index identifying the location of the menu item in the menu.

Return Value

The new menu item (an object conforming to the NSMenuItem protocol) or nil if the item could not be created

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSMenu.h

isTornOff

Returns a Boolean value that indicates whether the receiver is offscreen or attached to another menu (or if it’s the main menu).

- (BOOL)isTornOff
Return Value

NO if the receiver is offscreen or attached to another menu (or if it’s the main menu), otherwise YES.

Special Considerations

On OS X v10.6 and later this method has no effect.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

itemArray

Returns an array containing the receiver’s menu items.

- (NSArray *)itemArray
Return Value

An array containing the receiver’s menu items.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSMenu.h

itemAtIndex:

Returns the menu item at a specific location of the receiver.

- (NSMenuItem *)itemAtIndex:(NSInteger)index
Parameters
index

An integer index locating a menu item in a menu.

Return Value

The found menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be found.

Discussion

This method raises an exception if index is out of bounds.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

itemChanged:

Invoked when a menu item is modified visually (for example, its title changes).

- (void)itemChanged:(NSMenuItem *)anObject
Parameters
anObject

The menu item that has visually changed.

Discussion

This method is not called for changes involving the menu item's action, target, represented object, or tag. Posts an NSMenuDidChangeItemNotification.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

itemWithTag:

Returns the first menu item in the receiver with the specified tag.

- (NSMenuItem *)itemWithTag:(NSInteger)aTag
Parameters
aTag

A numeric tag associated with a menu item.

Return Value

The found menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be found.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

itemWithTitle:

Returns the first menu item in the receiver with a specified title.

- (NSMenuItem *)itemWithTitle:(NSString *)aString
Parameters
aString

The title of a menu item.

Return Value

The found menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be found.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

menuBarHeight

Returns the menu bar height for the current application’s main menu.

- (CGFloat)menuBarHeight
Return Value

The receiver's main menu bar height or 0.0 if the receiver is some other menu.

Discussion

This method supersedes the menuBarHeight class method of the NSMenuView class.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSMenu.h

menuChangedMessagesEnabled

Returns a Boolean value that indicates whether messages are sent to the application’s windows upon each change to the receiver.

- (BOOL)menuChangedMessagesEnabled
Return Value

YES if messages are sent to the application’s windows upon each change to the receiver, otherwise NO.

Special Considerations

On OS X v10.6 and later this method has no effect. This method may be deprecated in a future release.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

minimumWidth

Returns the minimum width of the menu.

- (CGFloat)minimumWidth
Return Value

The minimum width of the menu in screen coordinates.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

numberOfItems

Returns the number of menu items in the receiver, including separator items.

- (NSInteger)numberOfItems
Return Value

The number of menu items in the receiver, including separator items.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSMenu.h

performActionForItemAtIndex:

Causes the application to send the action message of a specified menu item to its target.

- (void)performActionForItemAtIndex:(NSInteger)index
Parameters
index

The integer index of a menu item.

Discussion

If a target is not specified, the message is sent to the first responder. As a side effect, this method posts NSMenuWillSendActionNotification and NSMenuDidSendActionNotification.

In OS X v10.6 and later the performActionForItemAtIndex: no longer triggers menu validation. This is because validation is typically done during menu tracking or key equivalent matching, so the subsequent performActionForItemAtIndex: validation was redundant. To trigger validation explicitly, use invoke the update method.

In OS X v10.6 performActionForItemAtIndex:, when called, now triggers highlighting in the menu bar. It also sends out appropriate accessibility notifications indicating the item was selected.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

performKeyEquivalent:

Performs the action for the menu item that corresponds to the given key equivalent.

- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
Parameters
theEvent

An NSEvent object that represents a key-equivalent event.

Return Value

YES if theEvent is a key equivalent that the receiver handled, NO if it is not a key equivalent that it should handle.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

popUpMenuPositioningItem:atLocation:inView:

Pops up the menu at the specified location.

- (BOOL)popUpMenuPositioningItem:(NSMenuItem *)item atLocation:(NSPoint)location inView:(NSView *)view
Parameters
item

The menu item to be positioned at the specified location in the view.

location

The location in the view coordinate system to display the menu item.

view

The view to display the menu item over.

Return Value

YES if menu tracking ended because an item was selected, and NO if menu tracking was cancelled for any reason.

Discussion

Pops up the receiver as a popup menu. The top left corner of the specified item (if specified, item must be present in the receiver) is positioned at the specified location in the specified view, interpreted in the view's own coordinate system.

If item is nil, the menu is positioned such that the top left of the menu content frame is at the given location.

If view is nil, the location is interpreted in the screen coordinate system. This allows you to pop up a menu disconnected from any window.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

propertiesToUpdate

Returns the available properties for the menu.

- (NSMenuProperties)propertiesToUpdate
Return Value

A bitwise-C OR of the values in the “NSMenuProperties” that are applicable to this menu.

Discussion

The propertiesToUpdate method may be called on the menu from specific callbacks to determine which properties the have been defined, and whether or not they are relevant to the changes you need to make. It is intended to allow more efficient updating of the menu in certain circumstances.

For example, if NSMenuPropertyItemImage is not set, your delegate does not need to update the images of the menu items, because the images are not needed (for example, during key equivalent matching). If the NSMenuPropertyItemImage bit is 0, you can avoid updating the menu's images, which may improve performance if computing the images is expensive.

You only have to update a property if it may have changed since you last set it, even if the corresponding bit is 1. For example, if the title of a menu item never changes, you only have to set it once.

You may call this from the menu delegate methods menuNeedsUpdate:, or the menu validation methods -validateMenuItem: or validateUserInterfaceItem:. Calling this at other times will raise an exception.

If a menu property does not have a corresponding bit, you should ensure it is always set properly after the callback returns.

Calling this is optional; it is always acceptable to fully update all properties of the menu.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

removeAllItems

Removes all the menu items in the receiver.

- (void)removeAllItems
Discussion

This method is more efficient than removing menu items individually.

Unlike the other remove methods, this method does not post NSMenuDidChangeItemNotification notifications.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

removeItem:

Removes a menu item from the receiver.

- (void)removeItem:(NSMenuItem *)anItem
Parameters
anItem

The menu item to remove.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSMenu.h

removeItemAtIndex:

Removes the menu item at a specified location in the receiver.

- (void)removeItemAtIndex:(NSInteger)index
Parameters
index

An integer index identifying the menu item.

Discussion

After it removes the menu item, this method posts an NSMenuDidRemoveItemNotification.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

setAllowsContextMenuPlugIns:

Sets whether the popup menu allows appending of contextual menu plugin items.

- (void)setAllowsContextMenuPlugIns:(BOOL)allows
Parameters
allows

YES if the popup menu should allow context menu plugin items to be appending, otherwise NO.

Discussion

Contextual menu plugins are system-wide services provided by other applications. For example, a contextual menu plugin might provide an “Open URL...” service. By enabling context menu plugins your application’s contextual menu will display the appropriate items for the currently selected data type.

See Services Implementation Guide for more information on contextual menu plugins.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

setAutoenablesItems:

Controls whether the receiver automatically enables and disables its menu items based on delegates implementing the NSMenuValidation informal protocol.

- (void)setAutoenablesItems:(BOOL)flag
Parameters
flag

If flag is YES, menu items are automatically enabled and disabled. If flag is NO, menu items are not automatically enabled or disabled.

Discussion

See the NSMenuValidation protocol specification for more information.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSMenu.h

setDelegate:

Sets the receiver’s delegate.

- (void)setDelegate:(id < NSMenuDelegate >)anObject
Parameters
anObject

The object to set as delegate.

Discussion

You can use the delegate to populate a menu just before it is going to be drawn and to check for key equivalents without creating a menu item.

Availability
  • Available in OS X v10.3 and later.
See Also
Declared In
NSMenu.h

setFont:

Sets the font used to display the menu and its submenus.

- (void)setFont:(NSFont *)font
Parameters
font

The font object to use.

Discussion

This font will be used to display the menu and any submenus that have not had their font set explicitly.

Availability
  • Available in OS X v10.6 and later.
See Also
Declared In
NSMenu.h

setMenuChangedMessagesEnabled:

Controls whether the receiver sends messages to the application’s windows upon each menu change.

- (void)setMenuChangedMessagesEnabled:(BOOL)flag
Parameters
flag

YES if the receiver should send a message at each menu change, NO otherwise.

Discussion

To avoid the “flickering” effect of many successive menu changes, invoke this method with flag set to NO, make changes to the menu, and invoke the method again with flag set to YES. This approach has the effect of batching changes and applying them all at once.

Special Considerations

On OS X v10.6 and later this method has no effect. This method may be deprecated in a future release.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

setMinimumWidth:

Set the minimum width of the menu.

- (void)setMinimumWidth:(CGFloat)width
Parameters
width

The minimum width of the menu in screen coordinates.

Discussion

The menu will not draw smaller than its minimum width, but may draw larger if it needs more space. The default value is 0.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

setShowsStateColumn:

Sets whether the receiver displays the state column.

- (void)setShowsStateColumn:(BOOL)showsState
Parameters
showsState

YES to display the state column, otherwise NO.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMenu.h

setSubmenu:forItem:

Assigns a menu to be a submenu of the receiver controlled by a given menu item.

- (void)setSubmenu:(NSMenu *)aMenu forItem:(NSMenuItem *)anItem
Parameters
aMenu

A menu object that is to be a submenu of the receiver.

anItem

A menu item (that is, an object conforming to the NSMenuItem protocol) that controls aMenu. The method sets the action of anItem to submenuAction:.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

setSupermenu:

Sets the receiver’s supermenu.

- (void)setSupermenu:(NSMenu *)supermenu
Parameters
supermenu

A menu object to set as the supermenu of the receiver.

Discussion

You should never invoke this method directly; it is public so subclassers can add behavior to the default implementation. Subclassers should call the superclass’s method as part of their implementation.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

setTitle:

Sets the receiver’s title.

- (void)setTitle:(NSString *)aString
Parameters
aString

A string to assign as the new title of the receiver.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSMenu.h

showsStateColumn

Returns a Boolean value that indicates whether the receiver displays the state column.

- (BOOL)showsStateColumn
Return Value

YES if the receiver displays the state column, otherwise NO.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSMenu.h

size

Returns the size of the menu.

- (NSSize)size
Return Value

The size of the menu in screen coordinates.

Discussion

The menu may draw at a smaller size when shown, depending on its positioning and display configuration.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSMenu.h

submenuAction:

The action method assigned to menu items that open submenus.

- (void)submenuAction:(id)sender
Discussion

You may override this method to implement different behavior. Never invoke this method directly.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

supermenu

Returns the receiver’s supermenu.

- (NSMenu *)supermenu
Return Value

The receiver’s supermenu or nil if it has none.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

title

Returns the receiver’s title.

- (NSString *)title
Return Value

The receiver’s title.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

update

Enables or disables the receiver’s menu items based on the NSMenuValidation informal protocol and sizes the menu to fit its current menu items if necessary.

- (void)update
Discussion

See the NSMenuValidation protocol specification for more information.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSMenu.h

Constants

NSMenuProperties

These constants are used as a bitmask for specifying a set of menu or menu item properties, used in the propertiesToUpdate.

enum {
   NSMenuPropertyItemTitle = 1 << 0,
   NSMenuPropertyItemAttributedTitle = 1 << 1
   NSMenuPropertyItemKeyEquivalent = 1 << 2,
   NSMenuPropertyItemImage = 1 << 3,
   NSMenuPropertyItemEnabled = 1 << 4,
   NSMenuPropertyItemAccessibilityDescription = 1 << 5
};
typedef NSUInteger NSMenuProperties;
Constants
NSMenuPropertyItemTitle

The menu item’s title.

Available in OS X v10.6 and later.

Declared in NSMenu.h.

NSMenuPropertyItemAttributedTitle

The menu item’s attributed string title.

Available in OS X v10.6 and later.

Declared in NSMenu.h.

NSMenuPropertyItemKeyEquivalent

The menu item’s key equivalent.

Available in OS X v10.6 and later.

Declared in NSMenu.h.

NSMenuPropertyItemImage

The menu image.

Available in OS X v10.6 and later.

Declared in NSMenu.h.

NSMenuPropertyItemEnabled

Whether the menu item is enabled or disabled.

Available in OS X v10.6 and later.

Declared in NSMenu.h.

NSMenuPropertyItemAccessibilityDescription

The menu item’s accessibility description.

Available in OS X v10.6 and later.

Declared in NSMenu.h.

Notifications

NSMenuDidAddItemNotification

Posted after a menu item is added to the menu. The notification object is the instance of NSMenu that just added the new menu item. The userInfo dictionary contains the following information:

Key

Value

@"NSMenuItemIndex"

An NSNumber object containing the integer index of the menu item that was added.

Availability
Declared In
NSMenu.h

NSMenuDidChangeItemNotification

Posted after a menu item in the menu changes appearance. Changes include enabling/disabling, changes in state, and changes to title. The notification object is the instance of NSMenu with the menu item that changed. The userInfo dictionary contains the following information:

Key

Value

@"NSMenuItemIndex"

An NSNumber object containing the integer index of the menu item that changed.

Availability
Declared In
NSMenu.h

NSMenuDidBeginTrackingNotification

Posted when menu tracking begins. The notification object is the main menu bar ([NSApp mainMenu]) or the root menu of a popup button. This notification does not contain a userInfo dictionary.
Availability
Declared In
NSMenu.h

NSMenuDidEndTrackingNotification

Posted when menu tracking ends, even if no action is sent. The notification object is the main menu bar ([NSApp mainMenu]) or the root menu of a popup button. This notification does not contain a userInfo dictionary.
Availability
Declared In
NSMenu.h

NSMenuDidRemoveItemNotification

Posted after a menu item is removed from the menu. The notification object is the instance of NSMenu that just removed the menu item. The userInfo dictionary contains the following information:

Key

Value

@"NSMenuItemIndex"

An NSNumber object containing the integer index of the menu item that was removed. Note that this index may no longer be valid and in any event no longer points to the menu item that was removed.

Availability
Declared In
NSMenu.h

NSMenuDidSendActionNotification

Posted just after the application dispatches a menu item’s action method to the menu item’s target. The notification object is the instance of NSMenu containing the chosen menu item. The userInfo dictionary contains the following information:

Key

Value

@"MenuItem"

The menu item that was chosen.

Availability
Declared In
NSMenu.h

NSMenuWillSendActionNotification

Posted just before the application dispatches a menu item’s action method to the menu item’s target. The notification object is the instance of NSMenu containing the chosen menu item. The userInfo dictionary contains the following information:

Key

Value

@"MenuItem"

The menu item that was chosen.

Availability
Declared In
NSMenu.h