Search code examples
cocoansmenunsmenuitem

Cocoa: Changing object property from different menu items


What's the rule of thumb if I want to change observed object's single property from different menu items (think - list of options).

E.g. I have an app that displays a car in a single window. I have a menu with menu item that says [Colors] with few submenu items like [Black, Green, Blue, Red, White, etc.]. How do I implement the mechanism behind this so that each submenu item changes same property (in this case - color) to different values.


Solution

  • If you're using target-action (IBAction) just point the menu at the same method in the same object and have the method make the appropiate changes.

    If you're using bindings, then you set the keypath to the same attribute.