以编程方式执行的方式(模拟) func textFieldShouldReturn(textField:UITextField) - > Bool 从输入附件视图中运行。
MyCustomInputView有DONE按钮。我想要 func textFieldShouldReturn(textField:UITextField) - >按下DONE按钮时,将为MyTextField代理触发Bool 。实现它的方法是什么?
class MyTextField: UITextField {
func setup() {
let myCustomInputView = MyCustomInputView()
self.inputAccessoryView = myCustomInputView
}
}
答案 0 :(得分:0)
我做了MyCustomInputView将具有UITextField的扩展功能。
class MyCustomInputView: UIView {
var textField: UITextField?
@IBAction func didClickReturnButton(sender: UIButton) {
if let textField = textField, let textFieldDelegate = textField?.delegate {
if textFieldDelegate.textFieldShouldReturn!(textField) {
textField.endEditing(true)
}
}
}
}