2016-02-01 72 views
0

以编程方式执行(模拟)的方式func textFieldShouldReturn(textField:UITextField) - > Bool函数来自输入附件视图。以编程方式从inputAccessoryView执行textFieldShouldReturn

MyCustomInputView有DONE按钮。我希望func textFieldShouldReturn(textField:UITextField) - > Bool将在按下DONE按钮时为MyTextField委托触发。实现它的方法是什么?

class MyTextField: UITextField { 

    func setup() { 
     let myCustomInputView = MyCustomInputView() 
     self.inputAccessoryView = myCustomInputView 
    } 
} 

回答

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) 
      } 
     } 
    } 
}