Set an NSButton's action to be the same as an NSMenuItem's
In my开发者_JAVA百科 application, I save user preferences and one of the preferences is whether to show any NSMenuItem
s 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
Check the following:
- message selector ([theItem action]) is not NULL.
- target for the newButton is set.
You will need to set the UIButton
instance's target
and action
properties. This question shows how.
精彩评论