如何将按钮连接到Mac OS X上的方法 [英] How to connect a button to a method on Mac OS X

查看:108
本文介绍了如何将按钮连接到Mac OS X上的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于为iPhone编程。在这里,我将一个按钮连接到一个动作,然后通过创建一个方法,如: - (IBAction)DoStuff {...} 。然后我会为按钮,然后在Interface Builder中的实际按钮创建一个插座。然后我将该按钮连接到插座,然后通过单击Touch Up Inside旁边的圆圈将其连接到文件的所有者并选择我的操作,将该按钮连接到操作。

I am used to programming for the iPhone. There, I would connect a button to an action, and then a method by creating the method like so: -(IBAction) DoStuff{…}. Then I would make an outlet for the button, and then the actual button in Interface Builder. I would then connect the button to the outlet, and then connect the button to the action by clicking on the circle next to Touch Up Inside and drag it over to File's Owner and select my action.

我是新的编程为Mac,所以我试图从performClick拖动到我想要的文件,但它不会让我建立连接。我必须以编程方式或做什么?

I am new to programming for the Mac, so I tried to drag from performClick to the file I wanted, but it wouldn't let me make the connection. Do I have to do this programmatically or what? How do I get this button to trigger an action in my code?

推荐答案

基本区别是iOS控件可以有多个动作对于不同的事件,但Mac OS X控件只有一个主要操作(在某些情况下,还有其他可以设置程序)。

The fundamental difference is that iOS controls can have multiple actions for different events, but Mac OS X controls only have one primary action (in some cases, there are others that can be set up programatically).

当您右键单击在Mac nib的按钮上, performClick:接收到的操作下;它不是一个事件。 已发送操作下的唯一条目是选择器,这是唯一可以连接到另一个对象上的操作。

When you right-click on a button in a Mac nib, performClick: is under Received Actions; it’s not an event. The only entry under Sent Actions is "selector", which is the only thing you can connect to an action on another object.

只有一个发送事件,你通常只是控制 - 从控件拖动/向右拖动到目标,并选择操作,而不是控制点击,选择事件并从中拖动。

Because there is only one "sent event", you’ll normally just control-drag/right-drag from the control to the target and select the action rather than control-clicking, selecting the event and dragging from that.

这篇关于如何将按钮连接到Mac OS X上的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆