在 NSButton 中存储指针

发布于 2024-12-19 05:57:21 字数 441 浏览 8 评论 0原文

我正在以编程方式设置一个带有目标对象的 NSButton ,并且我想将另一个对象传递给被调用的选择器。

据我所知,我只能将 NSButton 实例传递给选择器,因此我正在寻找一种方法来存储指向 NSButton 内部另一个对象的指针。

这可能吗?或者还有其他方法可以做到这一点吗?

示例:

[fooButton setAction:NSSelectorFromString(@"fooSelector:")];
[fooButton setTarget:myTargetHandler]

现在,我想在单击 fooButton 时将“myObject”传递给 myTargetHandler (fooSelector:) 。

I'm programmatically setting up a NSButton with a target object and I want to pass another object to the called selector.

As far as I know, I can only pass the NSButton instance to a selector, so I'm looking for a way to store a pointer to another object inside of my NSButton.

Is that possible or is there another way to do this?

Example:

[fooButton setAction:NSSelectorFromString(@"fooSelector:")];
[fooButton setTarget:myTargetHandler]

And now, I want to pass "myObject" to myTargetHandler (fooSelector:) when fooButton is clicked.

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

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

发布评论

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

评论(1

欢你一世 2024-12-26 05:57:21

您是否考虑过简单地继承 NSButton 并为此添加一个属性?您甚至可以通过一个简单的类别来实现它。

每个 UIControl 中还有一个 - (NSInteger)tag - 也许这有效?

Have you considered simply subclassing NSButton and adding a property for this? You may even be able to achieve it with a simple category.

There's also a - (NSInteger)tag in every UIControl - maybe that works?

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