<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/willOpenMenu(_:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(im)willOpenMenu:withEvent:"
  },
  "title" : "willOpenMenu(_:with:)"
}
-->

# willOpenMenu(_:with:)

Called just before a contextual menu for a view is opened on screen.

```
func willOpenMenu(_ menu: NSMenu, with event: NSEvent)
```

## Parameters

`menu`

The menu that will be opened.

`event`

The event that caused the menu to open.

## Discussion

This method is called just before a contextual menu for a view is opened on screen. It provides an opportunity to make any desired changes to the visual state of the view. For example, a table view might select a row in response to the contextual menu being displayed.

---

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)