1

I'm trying to disable a menuItem of a popUp button in a macOS app. I get to set the state to on or off (the checkmark of the menu item), but I haven't found a way to set the enabled to false (greyed out).

func disableMyItem() {
    let myItem = actionButton.item(withTitle: "Test Item") // creating the NSMenuItem object
    myItem?.state = NSOffState // remove checkmark
    myItem?.isEnabled = false // has no effect

    print(myItem?.isEnabled) // "Optional(false)"
}
Cue
  • 2,952
  • 3
  • 33
  • 54

1 Answers1

2

If you're using Interface Builder, uncheck "Autoenables" in the Attributes Inspector.

Screenshot showing exactly where that is

John Montgomery
  • 6,739
  • 9
  • 52
  • 68