Search code examples
objective-cmacoscocoansbuttonnsmenuitem

Set an NSButton's action to be the same as an NSMenuItem's


In my application, I save user preferences and one of the preferences is whether to show any NSMenuItems as buttons in the home window. I don't have problems to create the buttons dynamically, but I can't pass the action of the NSMenuItem to the NSButton. I have already tried:

[newButton setAction:[theItem action]];

UPDATE

I just have to set the target as self

[newButton setTargert:self];

And move the code to the class that send the action to the NSMenuItem


Solution

  • Check the following:

    1. message selector ([theItem action]) is not NULL.
    2. target for the newButton is set.