将 NSButton 的操作设置为与 NSMenuItem 的操作相同
在我的应用程序中,我保存用户首选项,其中首选项之一是是否在主窗口中将任何 NSMenuItem
显示为按钮。我动态创建按钮没有问题,但无法将 NSMenuItem
的操作传递给 NSButton
。我已经尝试过:
[newButton setAction:[theItem action]];
更新
我只需将目标设置为 self
[newButton setTargert:self];
并将代码移动到将操作发送到 NSMenuItem
的类
In my 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查以下内容:
Check the following:
您需要设置
UIButton
实例的target
和action
属性。 这个问题展示了如何实现。You will need to set the
UIButton
instance'starget
andaction
properties. This question shows how.