I have a UITextField
that can be set into editing mode.
Normally, editing is ended by entering „Done“ on the keyboard.
This calls textFieldDidEndEditing(_ textField: UITextField)
, where some housekeeping happens.
In rare cases, however, an alert is shown that the user entered a geofence. If the text field is then in editing mode, it resigns first responder status since the alert view becomes first responder, and textFieldDidEndEditing(_ textField: UITextField)
is also called. When the alert is dismissed, the first responder status of the text field is restored.
The problem:
I have to distinguish both cases:
If the text field ends editing because of a Done on the keyboard, housekeeping should happen.
If it ends editing because an alert was shown, housekeeping must not be done.
So, how can I distinguish both cases?
I tried to use the delegate function
textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason)
where reason
may be cancelled
or committed
, both in both cases the reason is committed
.