本文介绍了Swift:如何从 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)

这篇关于Swift:如何从 NSTextField 连续发送动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-02 23:25