I am using the approach described in this stackoverflow posting to retrieve values from a textfield. My problem is that the tableview is presented modally and I have a save
button that validates the input and stores it.
The problem is that the textFieldDidEndEditing
method is not called when the user clicks an UIBarButtonItem
(= the save button, which closes the modal view).
In this event (when the user wants to save the input) I would like to validate it. But the values are stored in properties in the textFieldDidEndEditing
. Due to the fact that this method is not called, I cannot validate the input values correctly.
Does anyone have a hint or solution on this?
Thanks in advance!
Okay, here we go:
Thanks to @Lefteris and his idea with storing the current index. Due to the fact that I cannot store the index into the
tag
attribute I decided to store the activeindexPath
and additionally the activetextField
. (I know, a reference to theUITextField
would have been enough but I needed it for other stuff)First I have added these two properties:
Then I implemented
textFieldDidBeginEditing:
andtextFieldDidEndEditing:
ofUITextFieldDelegate
.In
textFieldDidEndEditing:
I am storing the values into my properties (such asself.firstName
,self.lastName
, and so on...) by using the method[self assumeInput:input withIndexPath:self.activeIndexPath];
.In my
saveAction
-Method I am storing the value from the currently activeTextField
.... and that's it!
Hope it helps! Thanks to @Lefteris for his input.
Best, Chris
You should assign unique tag numbers to your text fields, then keep track on which is currently active (i.e. use a int iVar to store the active text fields tag value) in the
textFieldDidBeginEditing
delegate and when the user clicks the save, you should get the last textfield by it's tag value and then it's text value so you can validate it.