在 Interface Builder 中设置操作时控制拖动操作方向的重要性

发布于 2024-09-19 17:40:57 字数 954 浏览 2 评论 0原文

我有一个关于在使用 Interface Builder (3.2.3) 设置操作时选择控制拖动操作的正确起点和终点的重要性的问题。这个问题是在处理介绍性文本中的示例时出现的。在示例项目中,有一个非常简单的图形窗口,其中包含三个 NSTextField(即名字、姓氏、电子邮件)和一个 NSTextView。控制器类的接口在头文件中声明为:

@interface EmailController : NSObject {

 IBOutlet NSTextField *emailField;
 IBOutlet NSTextField *firstNameField;
 IBOutlet NSTextField *lastNameField;
 IBOutlet NSTextView *resultTextView;

}

- (IBAction)textFieldChanged:(id)sender;

@end

文本强调指出,当设置操作时,您将开始在控件上按住 Control 并拖动。具体来说,该示例首先从 First Name 可编辑 NSTextField 文本字段按住 Control 键拖动到 EmailController 实例,其中会出现一个黑色小窗口,并且可以选择操作 textFieldChanged 操作。

将名字可编辑框连接到操作后,文本会引导读者将姓氏和电子邮件可编辑框也连接到同一操作。然而,在这些情况下,文本会引导读者开始从小圆圈到控制器实例黑色窗口中 textFieldChanged 操作右侧的 Control 拖动操作,并在“姓氏”和“电子邮件”可编辑框处结束。这似乎与我理解的在设置动作时从控件开始的一般规则相反。

无论我选择哪一点作为起点和终点,我似乎都会得到相同的结果。连接器检查器中列出的各种对象的操作似乎总是与我选择的起点无关。如果不是它看起来与明确规定的一般规则相矛盾,我什至不会认为这是一个问题。当我尝试对插座做同样的事情时,我确实注意到了一个问题。

将控件连接到操作时选择哪个点作为起点重要吗?

谢谢

I have a question regarding the importance of choosing the correct starting and ending points of a control-drag operation while setting actions using Interface Builder (3.2.3). This issue came up while working through an example in an introductory text. In the example project there is a very simple graphical window with a three NSTextFields (i.e. First Name, Last Name, Email) and one NSTextView. The interface for the controller class is declared in the header file as:

@interface EmailController : NSObject {

 IBOutlet NSTextField *emailField;
 IBOutlet NSTextField *firstNameField;
 IBOutlet NSTextField *lastNameField;
 IBOutlet NSTextView *resultTextView;

}

- (IBAction)textFieldChanged:(id)sender;

@end

The text makes a point in stating that when setting an action you begin the control-drag at the control. Specifically, the example starts with a control-drag from the First Name editable NSTextField text field to the EmailController instance where a small black window appears and where the action textFieldChanged action can be selected.

After the First Name editable box is connected to the action the text directs the reader to also connect the Last Name and Email editable boxes to the same action. However in these cases the text directs the reader to start the control-drag operation from the small circle to the right side of the textFieldChanged action in the black window of the controller instance and to end at the Last Name and Email editable boxes. This seems opposite to how I understand the general rule of starting at the control while setting an action.

No matter which points I choose as my start and my end I seem to get the same result. The actions listed in the Connector Inspector for the various objects always seem indifferent to which point I choose as my start. I wouldn't even consider it an issue if it wasn't that it seemed contradictory to the explicitly stated general rule. I did notice a problem when I tried doing the same thing with outlets.

Does it matter which point you choose as the start when connecting a control to an action?

Thanks

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

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

发布评论

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

评论(1

酸甜透明夹心 2024-09-26 17:41:00

将控件连接到操作时选择哪个点作为起点重要吗?

不。

Big Nerd Ranch 建议始终从发送者拖动到接收者 (出口到对象或控件到目标)以明确消息将进入哪个方向。向另一个方向拖动同样有效,但不会向新的 Cocoa 和 Cocoa Touch 程序员强化消息方向。

(需要明确的是,该博客是由前 BNR 课程参与者撰写的,而不是由 BNR 或为 BNR 工作的任何人撰写的。)

将名字可编辑框连接到操作后,文本会引导读者将姓氏和电子邮件可编辑框也连接到同一操作。然而,在这些情况下,文本会引导读者开始从小圆圈到控制器实例黑色窗口中 textFieldChanged 操作右侧的 Control 拖动操作,并在“姓氏”和“电子邮件”可编辑框处结束。这似乎与我理解的从控件开始设置操作的一般规则相反。

右键单击操作接收器并从操作中拖动的方式的一个优点是更容易一次连接一堆操作。这听起来像是教程例外的最好理由,除了由不同的作者或不同的作者(我猜)以不同的做事方式之外。

Does it matter which point you choose as the start when connecting a control to an action?

No.

Big Nerd Ranch recommends always dragging from sender to receiver (outlet to object or control to target) to make clear which direction the message(s) will go in. It's equally valid to drag in the other direction, but does not reinforce the message direction to new Cocoa and Cocoa Touch programmers.

(To be clear, that blog is authored by a former BNR class attendee, not by BNR or anyone working for BNR.)

After the First Name editable box is connected to the action the text directs the reader to also connect the Last Name and Email editable boxes to the same action. However in these cases the text directs the reader to start the control-drag operation from the small circle to the right side of the textFieldChanged action in the black window of the controller instance and to end at the Last Name and Email editable boxes. This seems opposite to how I understand the general rule of starting at the control while setting an action.

One advantage of the right-click-on-action-receiver-and-drag-from-the-actions way is that it's easier to connect a bunch of actions at once. That sounds like the best reason for the tutorial making an exception there, aside from just being by a different author or authors (I'm guessing) with a different way of doing things.

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