我如何知道点击了哪个按钮?目标C
我正在作业中做 Presence1,这要求我构建一个多屏幕应用程序。 我有两个 ViewController,vc1 和 vc2。在vc1中,我有两个按钮。我对它们使用相同的方法,并且它们的标题相同。
我的问题是,当我更改为 vc2 时,如何知道在 vc1 中单击了哪个按钮?
有一个主题告诉我,当我单击按钮时,我应该获取鼠标的位置(x,y),但我认为这不太好。
I am doing Presence1 in Assignment which require me builds a multiple screens application.
I have two ViewController, vc1 and vc2. In vc1, i have two buttons. I use a same method for them and the title of them are same.
My question is How can i know which button is clicked in vc1 when i change to vc2?
There are a topic show me that I should get positions (x,y) of mouse when i click on button, but i think it is not quite good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的答案会起作用。如果您不想保留按钮的插座,您可以在界面生成器中为它们分配标签。例如,您为按钮 1 分配标签值 1,为按钮 2 分配标签值 2。然后在代码中
The answer above would work. If you don't want to keep outlets for the buttons you can assign them tags in interface builder. As an example, you assign button 1 a tag value of 1 and button 2 a tag value of 2. Then in the code
如果您有两个
NSButton
属性,例如:那么您可以将发送者与按钮指针进行比较:
这就是您想要的吗?
If you have two
NSButton
properties such as:Then you can compare the sender with the button pointer:
Is that what you're after?