I have a problem with the event sequence of the UITextFieldDelegate
.
I have two UITableView
A and B which are hosted by two UIViewController
A and B which are themselves hosted by a container view each as follows (cells omitted from the drawing):
Tableview B has textfields (UITextField
) in its cells with the following delegate functions implemented.
func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason)
{
if reason == .committed
{
...save content of textfield...
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool
{
textField.resignFirstResponder()
...save content of textfield...
return true
}
The user can, after entering text in the field either hit the return key or tap somewhere outside to save the data. This works as long as the user taps somewhere within viewcontroller B.
If the user taps somewhere within tableview A, the tableview's
tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
function is called first and only after that, the textfield delegates are called.
As the tableView(_:didSelectRowAt:)
loads new data into tableview B this is obviously a problem.
I tried textFieldShouldEndEditing
as proposed here but it is still only called after didSelectRowAt
How can I receive an event that the user ended editing the field before any other events triggered?