繁体   English   中英

自定义键盘:文本更新时得到通知

[英]Custom keyboard: get notified when text updates

自定义键盘修改的文本更新时, UIInputViewController是否有方法? textWillChange / textDidChange仅通知我有关光标移动的信息。

子类UIInputView 在您的子类中,设置一个protocol

protocol MyCustomInputViewDidChangeDelegate {
    func customInputViewDidChange(customInputView: MyCustomInputView)
}

class MyCustomInputView: UIInputView {
    var delegate: MyCustomInputViewDidChangeDelegate?
}

UIInputViewController符合MyCustomInputViewDidChangeDelegate情况。触摸自定义键盘时,请在适当的时候通过调用delegate?.customInputViewDidChange(self)将其传播给委托。

您可以使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM