Differences between `.EditingDidEnd` and `.EditingDidEndOnExit`
Asked Answered
M

3

27

What exactly are the differences between the UIControlEvents .EditingDidEnd and .EditingDidEndOnExit, and how do they relate to each other?

The documentation on UIControl is pretty vague, and has no information of whether these fire for different reasons, if one is a superset of the other, or if they're functionally equivalent.

The possibility of one being a superset is especially confusing, since the naming implies that .EditingDidEndOnExit is a specific occurrence of .EditingDidEnd, but the documentation seems to imply the opposite.

Maryjanemaryjo answered 18/2, 2015 at 19:37 Comment(0)
S
36

".EditingDidEnd" is called when somebody touches outside of the bounds of the text field, because they're likely about to interact with some other control or object.

"EditingDidEndOnExit" is called when the user clicks the "return" key in the keyboard (and you're right, it's not clear in the documentation... but if you look at the UIControl.h file you'll see a comment reflecting this point).

Softspoken answered 18/2, 2015 at 19:42 Comment(2)
EditingDidEndOnExit does dismiss the keyboard. But EditingDidEnd seems dismiss if I click in another text field, but not in any-other location (off-a-field)Privett
If I have a UITextField with both, I see tapping the return triggering both... like EditingDidEndOnExit; EditingDidEnd. When I add logging to wrap the target action, they seem to be run on separate threads, because the output is interlaced.Privett
S
9

From the UIControl header:

UIControlEventEditingDidEnd       = 1 << 18,
UIControlEventEditingDidEndOnExit = 1 << 19,     // 'return key' ending editing

So one is when the return key was pressed, the other is from touching outside of the bounds.

Schoof answered 18/2, 2015 at 19:43 Comment(0)
H
0

When a user taps on the return key of the keyboard, the following events are executed in order:

  • editingDidEndOnExit
  • primaryActionTriggered
  • editingDidEnd

When a user taps another UITextField or UITextView object, only 'editingDidEnd' is executed.

When app code executes 'resignFirstResponder()' on a given UITextField, only 'editingDidEnd' is executed.

When app code executes 'endEditing(true|false)' on a given UITextField, only 'editingDidEnd' is executed.

When app code executes 'becomeFirstResponder()' on another UITextField, only 'editingDidEnd' is executed.

When a user taps on the return key of the keyboard and textField has a delegate, the following events are executed in order:

  • delegate: textFieldShouldReturn
  • editingDidEndOnExit
  • primaryActionTriggered
  • editingDidEnd
  • delegate: textFieldDidEndEditing

Keyboard will dismiss if one or both following events will be supported:

  • textField.addTarget(self, action: #selector(editingDidEndOnExit), for: .editingDidEndOnExit)
  • textField.addTarget(self, action: #selector(primaryActionTriggered), for: .primaryActionTriggered)

Checked on iOS 16.2

Hame answered 8/2, 2023 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.