Search code examples
cocoansbuttonnsmenuitemnsmenu

Popped Up NSMenu Always Highlights First NSMenuItem


I have an NSButton that when clicked calls [NSMenu popUpMenuPositioningItem:atLocation:inView:]. The menu pops up in the proper location however the topmost NSMenuItem is always highlighted blue, as if the mouse was hovering over it, except that it's not. I can't seem to find any way to control the highlight of an NSMenuItem.

Looking at the screenshot you can see the menu is highlighted even though the mouse is still hovering over the NSButton.

enter image description here

How can I fix this? I don't want anything to be highlighted upon clicking the NSButton.


Solution

  • If you pass nil for the first argument in popUpMenuPositioningItem:atLocation:inView:, then nothing is selected.