Post

Replies

Boosts

Views

Activity

Reply to How do I set a menu check mark at runtime?
Is this what you are looking for:2019-12-08 22:33:32.117410+0100 Edgar[2669:436738] [Nib Loading] Failed to connect (object) outlet from (Edgar.AppDelegate) to (NSMenuItem): missing setter or instance variable2019-12-08 22:33:32.162887+0100 Edgar[2669:436738] Metal API Validation EnabledactionForItem Subject NSControlStateValue(rawValue: 1)The following is beyond my knowledge of XCode:Check also what image is defined for the menu item "Subject" in IB Attributs inspector for the on state field.
Dec ’19
Reply to How do I set a menu check mark at runtime?
I connect the menu action in IB by connecting to actionForItem(_ sender: NSMenuItem)and not elsewhere in code.You enable the menuItem in the IBAction: myItemSubmenu?.item(withTitle: "Subject")?.isEnabled = trueThe state before was Enabled (not greyed out) and without check mark.I would expect the code to put a check mark next to the item.
Dec ’19
Reply to How do I set a menu check mark at runtime?
I apologize for being so vague, but I hope the following helps:I forgot to mention I'm trying to make trial code for macOS. @IBOutlet weak var textResult: NSTextField! // Textbox for test purpose @IBAction func actionForItem(_ sender: NSMenuItem) { sender.state = sender.state == NSControl.StateValue.on ? NSControl.StateValue.off : NSControl.StateValue.on textResult.stringValue = "Clicked on = " + sender.title // For test purpose// The following is hardcoded for test purpose let mainMenu = NSApplication.shared.mainMenu! let firstMenu = mainMenu.item(withTitle: "Word class")?.menu let myItemSubmenu = firstMenu?.item(withTitle: "Noun group")?.submenu // will be nil if there is not submenu (hierarchical) myItemSubmenu?.item(withTitle: "Subject")?.isEnabled = true }
Dec ’19
Reply to How do I set a menu check mark at runtime?
I hope thiis example clarifies things:I have a user provided list of words, which the user classifiesWord class Noun group Subject Object Pronoun Personal IndefiniteI.e. Subject, Object, Personal, Indefinite may be (un)checked by the userand the word is stored along with the checked item's name(s) (sender.title)which I wish to use to restore the checkmark(s) for a given word.
Dec ’19