<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSMenuDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSMenuDelegate"
  },
  "title" : "NSMenuDelegate"
}
-->

# NSMenuDelegate

The optional methods implemented by delegates of [`NSMenu`](/documentation/AppKit/NSMenu) objects to manage menu display and handle some events.

```
protocol NSMenuDelegate : NSObjectProtocol
```

## Topics

### Handling Keyboard Equivalents

[`-  menuHasKeyEquivalent:forEvent:target:action:`](/documentation/AppKit/NSMenuDelegate/menuHasKeyEquivalent(_:for:target:action:))

Invoked to allow the delegate to return the target and action for a key-down event.

### Updating Menu Layout

[`-  menu:updateItem:atIndex:shouldCancel:`](/documentation/AppKit/NSMenuDelegate/menu(_:update:at:shouldCancel:))

Invoked to let the delegate update a menu item before it is displayed.

[`-  confinementRectForMenu:onScreen:`](/documentation/AppKit/NSMenuDelegate/confinementRect(for:on:))

Invoked to allow the delegate to specify a display location for the menu.

### Handling Highlighting

[`-  menu:willHighlightItem:`](/documentation/AppKit/NSMenuDelegate/menu(_:willHighlight:))

Invoked to indicate that a menu is about to highlight a given item.

### Handling Open and Close Events

[`-  menuWillOpen:`](/documentation/AppKit/NSMenuDelegate/menuWillOpen(_:))

Invoked when a menu is about to open.

[`-  menuDidClose:`](/documentation/AppKit/NSMenuDelegate/menuDidClose(_:))

Invoked after a menu closed.

### Handling Tracking

[`-  numberOfItemsInMenu:`](/documentation/AppKit/NSMenuDelegate/numberOfItems(in:))

Invoked when a menu is about to be displayed at the start of a tracking session so the delegate can specify the number of items in the menu.

[`-  menuNeedsUpdate:`](/documentation/AppKit/NSMenuDelegate/menuNeedsUpdate(_:))

Invoked when a menu is about to be displayed at the start of a tracking session.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)