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?