I have a tableview controller inside a navigation controller. This table simply shows one textfield in each row. In my navigation controller I have a “Done” navigation item that gets all the values entered in the textfields and shows the next screen.
The tableview controller implements UITextFieldDelegte and textFieldDidEndEditing to store the values of every textfield in its datasource (array of strings). In cellForRowAtIndexPath I also assign the delegate of the text fields to themselves. This all works well if I tap on the different textfields, I see how the datasource is properly updated.
My problem is when I do this sequence: type a value in one text field and then tap on the “Done” navigation item. I see that textFieldDidEndEditing is not called so the value is not stored. I also tried with textFieldShouldReturn and textFieldShouldReturn but nothing.
I have read many similar posts and I think the problem is that the "event" is being caught by prepareForSegue instead of textFieldDidEndEditing. If this is correct, I don’t know how to deal with this since I don’t know how to identify the indexPath of that “last edited textfield” when the Done is tapped.
Another related question: I have seen two approaches to get the indexPath of the cell containing the textfield when textFieldDidEndEditing is called:
1) textField.convertPoint + tableView.indexPathForRowAtPoint
2) tableView.indexPathForCell + textField.superview
Both seem to work well without differences (except for the issue that I just stated). Is any approach better than another?
Many thanks in advance for your help!!!
PS: if possible, in Swift code, please!