[英]Custom keyboard: get notified when text updates
Is there a method in UIInputViewController
when the text that the custom keyboard is modifying updates? 自定义键盘修改的文本更新时,
UIInputViewController
是否有方法? textWillChange
/ textDidChange
only notify me about cursor movement. textWillChange
/ textDidChange
仅通知我有关光标移动的信息。
Subclass UIInputView
. 子类
UIInputView
。 In your subclass, set up a protocol
. 在您的子类中,设置一个
protocol
。
protocol MyCustomInputViewDidChangeDelegate {
func customInputViewDidChange(customInputView: MyCustomInputView)
}
class MyCustomInputView: UIInputView {
var delegate: MyCustomInputViewDidChangeDelegate?
}
You'll have UIInputViewController
conform to MyCustomInputViewDidChangeDelegate
When your custom keyboard is touched, propagate that to the delegate when appropriate by calling delegate?.customInputViewDidChange(self)
. 您
UIInputViewController
符合MyCustomInputViewDidChangeDelegate
情况。触摸自定义键盘时,请在适当的时候通过调用delegate?.customInputViewDidChange(self)
将其传播给委托。
there are UITextFieldTextDidBeginEditingNotification, UITextFieldTextDidEndEditingNotification, UITextFieldTextDidChangeNotification You can use 您可以使用UITextFieldTextDidBeginEditingNotification,UITextFieldTextDidEndEditingNotification,UITextFieldTextDidChangeNotification
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.textFieldDidChanged(_:)), name: UITextFieldTextDidEndEditingNotification, object:self.txtAlbumName)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.textFieldDidChanged(_:)), name: UITextFieldTextDidChangeNotification, object:self.txtAlbumName)
// ------------
func textFieldDidChanged(sender:NSNotification) -> Void {
}
func textFieldDidChanged (sender:NSNotification) -> Void{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.