I am sure this is in the Apple documentation or must have been answered somewhere on this forum, since it seems so basic, but I could not find it nor a particularly elegant solution myself.
What I have is a UIViewController that pushes an editing view on its navigation stack. The editing view has a bunch of UITextFields in it. If one of them is being editing when the back button is touched, the original view's ViewWillAppear method is called before either the UITextField delegate methods of textFieldShouldEndEditing or textFieldDidEndEditing, or the IB linked action textFieldEditingEnded method are called.
Here is some code that I hope will make it clearer:
In the UIViewController:
- (void) viewWillAppear: (BOOL) animated {
[super viewWillAppear: animated];
NSLog( @"Entering view will appear for master view" );
nameLabelField.text = objectToEdit.name;
}
- (IBAction) editMyObject: (id) sender {
NSLog( @"Editing the object" );
EditViewController *evc = [[EditViewController alloc] initWithNibName: @"EditTableView" bundle: nil];
evc.editedObject = objectToEdit;
[self.navigationController pushViewController: evc animated: YES];
[evc release];
}
In the EditViewController <UITextFieldDelegate>:
- (void) viewWillAppear: (BOOL) animated {
[super viewWillAppear: animated];
nameField.text = editedObject.name;
}
- (void) viewWillDisappear: (BOOL) animated {
[super viewWillDisappear: animated];
NSLog( @"In viewWillDisappear" );
if( [self.navigationController.viewControllers indexOfObject: self] == NSNotFound ) {
NSLog( @"-- We are not in controller stack... the back button has been pushed" );
}
}
- (BOOL) textFieldShouldEndEditing: (UITextField *) textField {
NSLog( @"In textFieldShouldEndEditing" );
// Store text field value here???
// editedObject.name = nameField.text;
return Y