开发者

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

开发者 https://www.devze.com 2023-04-03 19:27 出处:网络
In my开发者_JAVA百科 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 dyna

In my开发者_JAVA百科 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


Check the following:

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


You will need to set the UIButton instance's target and action properties. This question shows how.

0

精彩评论

暂无评论...
验证码 换一张
取 消