2

The Context
I'm populating a TableView's NSPopupMenuCell's menu via Cocoa Bindings. All is well (I've bound 'Content', 'Content Values' and 'Selected Objects'). The menu is correctly populated at runtime and the underlying variable is properly being set (via KVC). Everything works on that end.

My Problem
Next I'd like to control the state of the populated menu items (as some would need to be disabled). Now I've read Apple's documentation on Enabling Menu Items very carefully… but for the life of me I can't seem to implement validateMenuItem: nor validateUserInterfaceItem: where they would actually get called.

I've tried, amongst other things, implementing these methods in the already existing App delegate but no joy. Am I perhaps misunderstanding something with the First Responder chain?

Also, logically, the other possibility is that the menu items actually do have Targets (the above assumes they don't). But, again, I can't seem to be able to identify their targets (so that I may implement validateMenuItem: there).

  • Possible duplicate of [Binding an NSMenuItem's title breaks enabled/disabled validation](http://stackoverflow.com/questions/3337233/binding-an-nsmenuitems-title-breaks-enabled-disabled-validation) – matt Apr 22 '17 at 02:54

2 Answers2

1

The Target of dynamically (via bindings) created NSMenuItem in a NSPopupMenuCell, turns out to be the NSPopupMenuCell itself (so you can subclass it and implement validateMenuItem: there).

I would imagine it's because NSPopupMenuCell would need to perform KVC calls (i.e. setValue:forKey:).

0

If you're using bindings to prepare the contents, you can also bind each NSMenuItem's enabled property to a boolean in the model expressing whether it should be enabled.

  • But the NSMenuItems are dynamically generated via the previously mention bindings… there's only a stand-in menu item within the XIB and setting its 'Enabled' binding(s), while being called, isn't affecting the menu item states (nor anything observable). Am I misunderstanding something here?! –  Nov 11 '11 at 00:52