0

There has been lots of questions on how to detect when a user presses DELETE button on a UITextField. However, playing around with it I realised it is only possible to trigger an event/action to run custom code when there is actually content in the UITextField. If the UITextField is empty and the user hits DELETE, no action will be fired on iOS.

I tried the following actions: Editing Changed, Editing Did Begin, Editing Did End, Value Changes. Also tried the delegate approach: textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool

The task I am looking to achieve is related to having a "type your pin code" screen where a user can type in a 6-digits numeric code gotten from SMS message. Since each UITextField represents a digit, once the user hits DELETE, the app should clear the UITextField just before the current one.

Any ideas whether this is possible on iOS?

Fabio Moggi
  • 405
  • 1
  • 4
  • 12
  • It's much simpler to have one off-screen text field that the user types into. Based on the value in that one text field, you update the onscreen representation with 0 to 6 dots or whatever as needed. – rmaddy Apr 29 '19 at 21:31
  • I like this approach. How would it be? – Fabio Moggi May 09 '19 at 06:33

0 Answers0