3

I have created a custom inputView and have a Done button. Does anyone know how I can wire the done button up to work the same as a return key on the built in keyboard.

I basically need to get the textFieldShouldReturn method to fire for a UITextField.

I know I can call resignFirstResponder on the textfield, but this does not fire the textFieldShouldReturn method.

Craig Mellon
  • 5,399
  • 2
  • 20
  • 25
  • This is a very old question, I am curious, could you find a way to fire textFieldShouldReturn without a custom UITextField? – patrickS Dec 22 '20 at 16:23

1 Answers1

0

If it's a custom input view, and a custom "Done" button, why do you need to use the text field delegate methods? You can wire the done button to your own action.

If you have some common code in your textFieldShouldReturn method this could be moved out to another method which can be called from the delegate method and your new action.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • I have thought of that, and will probably have to implement it this way, however I would have preferred to try and keep my custom keyboard generic enough that it used the built in textfield delegate methods. – Craig Mellon Sep 19 '11 at 09:47
  • Oh, OK - if it's a custom keyboard then presumably you already have a mechanism for passing new characters to the text field - what happens if you pass the return character? – jrturton Sep 19 '11 at 09:57
  • I couldn't find a mechanism for passing characters to text field, so I had to resort to adding a textField property on my keyboard and i'm simply modifying the text value on a key press. – Craig Mellon Sep 19 '11 at 10:05
  • So, what happens if you modify the text value to have a newline character on the end? I imagine the standard keyboard does something similar to what you are doing. – jrturton Sep 19 '11 at 10:14