简体   繁体   English

如何在我的子类NSTextField / NSTextFieldCell中使用“全选”?

[英]How can I get “Select All” working in my subclassed NSTextField/NSTextFieldCell?

Generally, when editing text in a text field/input/area/editor, pressing ⌘A will select all of the current text in said field/input/area/editor. 通常,在文本字段/输入/区域/编辑器中编辑文本时,按⌘A将选择所述字段/输入/区域/编辑器中的所有当前文本。 I've subclassed NSTextField and NSTextFieldCell, and no matter what I try, I can't seem to get basic "Select All" functionality working. 我已经将NSTextField和NSTextFieldCell子类化了,无论我尝试什么,我似乎无法获得基本的“全选”功能。 I've tried implementing delegate protocols, intercepting events, manipulating commands made by selectors, and every other thing I can think of. 我已经尝试过实现委托协议,拦截事件,操纵选择器生成的命令,以及我能想到的所有其他事情。 What gives? 是什么赋予了? (I can already hear the "Ever heard of Google?" refrains because of how simple this probably is, but I haven't found a single answer out there. I guess I can thank iOS for that.) (我已经可以听到“曾经听说过谷歌?”因为这可能有多简单,但我没有找到一个单一的答案。我想我可以感谢iOS。)

And before I forget to mention it, I also dragged a standard NSTextField into my nib to see if a non-subclassed NSTextField implements Select All behavior by default, and to my shock, it doesn't. 在我忘记提及它之前,我还将一个标准的NSTextField拖到我的nib中,看看默认情况下非子类NSTextField是否实现了Select All行为,而且我的震惊,它没有。 Am I going crazy here, or am I completely overlooking something? 我在这里疯了,还是我完全忽略了什么? Isn't Select All almost a requirement when implementing a text field? 在实现文本字段时,选择All几乎不是必需的吗? Apple's First Responder proxy handles everything under the sun (including two versions of selectAll ( selectAll and selectAll: ), but the n00b is strong with me, and I can't seem to make sense of any of this. Apple的First Responder代理处理太阳下的一切(包括两个版本的selectAll( selectAllselectAll: ),但是n00b对我来说很强大,我似乎无法理解这一点。

Any help/ideas would be immensely appreciated. 任何帮助/想法将非常感激。 Cheers! 干杯!

The application menu handles sending the keyboard shortcut actions to the application's current first responder. 应用程序菜单处理将键盘快捷键操作发送到应用程序的当前第一响应者。 The missing connection would explain why your regular NSTextField objects are missing this functionality as well. 缺少的连接将解释为什么您的常规NSTextField对象也缺少此功能。

Xcode 5中Interface Builder中的连接操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM