将 NSButton 的操作设置为与 NSMenuItem 的操作相同

发布于 2024-12-03 12:51:50 字数 355 浏览 8 评论 0原文

在我的应用程序中,我保存用户首选项,其中首选项之一是是否在主窗口中将任何 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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨洒年华 2024-12-10 12:51:50

检查以下内容:

  1. 消息选择器([theItem action])不为 NULL。
  2. newButton 的目标已设置。

Check the following:

  1. message selector ([theItem action]) is not NULL.
  2. target for the newButton is set.
梨涡 2024-12-10 12:51:50

您需要设置 UIButton 实例的 targetaction 属性。 这个问题展示了如何实现。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文