Swift: How to continuously send an action from a NSTextField

隐身守侯 提交于 2019-12-23 04:43:46

问题


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)?


回答1:


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.



来源:https://stackoverflow.com/questions/34817896/swift-how-to-continuously-send-an-action-from-a-nstextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!