简体   繁体   English

NSTextField GotFocus事件可可雨燕

[英]NSTextField GotFocus Event Cocoa Swift

In swift Cocoa is there an event that fires when a NSTextField gets focus for editing. 快速的Cocoa中有一个事件,当NSTextField获得焦点进行编辑时将触发该事件。 I Come from C# which has GotFocus() and LostFocus() Events. 我来自具有GotFocus()和LostFocus()事件的C#。

For NSTextfield I could find only these functions which fire after one starts typing. 对于NSTextfield,我只能找到在开始键入后会触发的这些函数。 Not as soon as focus is gained. 不能一。而就。

 override func controlTextDidBeginEditing(obj: NSNotification) {
 }

 func control(control: NSControl, textShouldBeginEditing fieldEditor: NSText) -> Bool {

 }

I Need this because as soon as someone starts editing, I want to show more detail. 我需要这个,因为一旦有人开始编辑,我想显示更多细节。 I have a simpler display name, and full name for editing. 我有一个更简单的显示名称,以及用于编辑的全名。

Thanks, 谢谢,

You can subclass NSTextField and override becomeFirstResponder and resignFirstResponder. 您可以继承NSTextField的子类,并覆盖beginFirstResponder和resignFirstResponder。 Please check this link How to detect when NSTextField has the focus or is it's content selected cocoa 请检查此链接如何检测NSTextField何时具有焦点或内容是否处于选中状态

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

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