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 active indexPath
and additionally the active textField
. (I know, a reference to the UITextField
would have been enough but I needed it for other stuff)
First I have added these two properties:
@property (nonatomic, strong) NSIndexPath *activeIndexPath;
@property (nonatomic, strong) UITextField *activeTextField;
Then I implemented textFieldDidBeginEditing:
and textFieldDidEndEditing:
of UITextFieldDelegate
.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSIndexPath *indexPath = (NSIndexPath*)[self.tableView indexPathForCell:(UITableViewCell*)[[textField superview] superview]];
self.activeTextField = textField;
self.activeIndexPath = indexPath;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *input = textField.text;
//assuming values from input textfield into corresponding properties
[self assumeInput:input withIndexPath:self.activeIndexPath];
self.activeTextField = nil;
self.activeTextField = nil;
}
In textFieldDidEndEditing:
I am storing the values into my properties (such as self.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 active TextField
.
- (IBAction)saveButtonClicked:(UIBarButtonItem *)sender
{
//assuming input from active field (didEndEditing _not_ called right now!)
[self assumeInput:self.activeTextField.text withIndexPath:self.activeIndexPath];
//test output
NSLog(@"firstName: %@", self.firstName);
NSLog(@"lastName: %@", self.lastName);
NSLog(@"email: %@", self.email);
...
}
... and that's it!
Hope it helps! Thanks to @Lefteris for his input.
Best,
Chris