在 NSButton 中存储指针
我正在以编程方式设置一个带有目标对象的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过简单地继承 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?