[英]Swift: How to continuously send an action from a NSTextField
I have a NSTextField
and want to send an action whenever the user changes the value. 我有一个
NSTextField
,想在用户更改值时发送一个动作。 I checked "Continuous" in the Interface Builder (which works ie fine with NSSlider), but the NSTextField only sends his action if I unfocus it. 我在Interface Builder中检查了“ Continuous”(可以在NSSlider上很好地工作),但是NSTextField仅在我不集中精力时才发送他的动作。 How can I continuously send an action from a NSTextField (using Swift)?
如何连续从NSTextField发送动作(使用Swift)?
Set the delegate of the text field to the class which is supposed to receive the action and implement 将文本字段的委托设置为应该接收操作并实现的类
func controlTextDidChange(_ obj: NSNotification)
This method is invoked when text in a control such as a text field or form changes.
当控件(例如文本字段或表单)中的文本更改时,将调用此方法。 The control posts a
NSControlTextDidChangeNotification
notification, and if the control's delegate implements this method, it is automatically registered to receive the notification.控件发布
NSControlTextDidChangeNotification
通知,并且如果控件的委托实现了此方法,则会自动注册该控件以接收该通知。 Use the key @"NSFieldEditor" to obtain the field editor from the userInfo dictionary of the notification object.使用键@“ NSFieldEditor”从通知对象的userInfo字典中获取字段编辑器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.