0
votes

What is the way programmatically execute (simulate) func textFieldShouldReturn(textField: UITextField) -> Bool function from the input accessory view.

MyCustomInputView have DONE button. I want that func textFieldShouldReturn(textField: UITextField) -> Bool will be triggered for MyTextField delegates when DONE button pressed. What is the way to achieve it?

class MyTextField: UITextField {

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

1 Answers

0
votes

I did extended functionality that MyCustomInputView will have 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)
            }
        }
    }
}