[英]NSTextView - How to detect when it is clicked?
I'm trying to do this: 我正在尝试这样做:
- (IBAction)textFieldSelected:(id)sender
{
printf("clicou no text\n");
}
I "connect" this to my NSTextField through the Interface Builder. 我通过“界面生成器”将此“连接”到我的NSTextField。
When I first start the app, the this NSTextField is already focused . 当我第一次启动该应用程序时, 此NSTextField已经聚焦 。 Then I click on a second NSTextField, and my first one lose the focus and I get the print statement.
然后,我单击第二个NSTextField,而第一个NSTextField失去了焦点,得到了打印语句。 Clicking back and forth between theses NSTextField I see that the print statement is just called when I click on the NSTextField that it is not attached to it.
在这些NSTextField之间来回单击,我看到当我单击未附加到它的NSTextField时,只是调用了打印语句。 I believe that it just happens when the first one loses the focus.
我相信这只是在第一个失去焦点时发生。
Q1: How do I do to have this print statement when the use click on the NSTextField (when it gets the focus)? 问题1:如何在使用时单击NSTextField(当获得焦点时)具有此打印语句?
Q2: How do I avoid it to get the focus automatically when the app starts? 问题2:如何避免启动应用程序时自动获得焦点?
Create the custom class of NSTextfield and then implement below method, so that whenever focus goes to the textfield below method will get called:- 创建NSTextfield的自定义类,然后实现下面的方法,以便每当焦点移到下面的文本字段时,都将被调用:
-(Bool)becomeFirstResponder{
return YES}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.