0

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

4

2 回答 2

0

有 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{

  }
}
于 2016-09-03T00:58:09.607 回答
0

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

protocol MyCustomInputViewDidChangeDelegate {
    func customInputViewDidChange(customInputView: MyCustomInputView)
}

class MyCustomInputView: UIInputView {
    var delegate: MyCustomInputViewDidChangeDelegate?
}

您将UIInputViewController遵守MyCustomInputViewDidChangeDelegate当您的自定义键盘被触摸时,在适当的时候通过调用将其传播给委托delegate?.customInputViewDidChange(self)

于 2016-09-03T00:36:21.647 回答