I can get the name of a NSMenuItem
at the top level of the NSMenu
of a NSPopUpButton
.
I do this by adding an action to the NSPopUpButton
:
@IBAction func menuDropdownAction(_ sender: Any) {
let titleOfSelectedItem = (sender as AnyObject).titleOfSelectedItem
print (titleOfSelectedItem! as Any)
}
But if I add a submenu to the NSMenu
it just returns nil
.
It seems to me that .titleOfSelectedItem
applied to the NSPopUpButton
should work for items buried in its submenus, but it seems not!
Any assistance would be gratefully accepted, there is a similar question, but its over 10 years old for cocoa and was no use to me. link