Swift:如何从 NSTextField 连续发送动作 [英] Swift: How to continuously send an action from a NSTextField
问题描述
我有一个 NSTextField
并且想在用户更改值时发送一个操作.我在 Interface Builder 中检查了Continuous"(它在 NSSlider 中工作正常),但是 NSTextField 只有在我不聚焦时才会发送他的动作.如何从 NSTextField 连续发送动作(使用 Swift)?
将文本域的委托设置为应该接收动作并实现的类
func controlTextDidChange(_ obj: NSNotification)
<块引用>
当控件中的文本(例如文本字段或形式变化.控件发布一个 NSControlTextDidChangeNotification
通知,如果控件的委托实现了这个方法,它自动注册以接收通知.使用钥匙@"NSFieldEditor" 从userInfo获取字段编辑器通知对象字典.
I have a NSTextField
and want to send an action whenever the user changes the value. I checked "Continuous" in the Interface Builder (which works i.e. fine with NSSlider), but the NSTextField only sends his action if I unfocus it. How can I continuously send an action from a NSTextField (using 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. Use the key @"NSFieldEditor" to obtain the field editor from the userInfo dictionary of the notification object.
这篇关于Swift:如何从 NSTextField 连续发送动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!