Dear fellow programmers,
What is the best way to pass information from a child in a navigation stack up one or more levels? I have searched online and can't seem to find the best way to begin implementing this.
Specifically this is my model: I have a grouped table view with several rows. When a user clicks on a row I take them to an MVC .ie click on 'select date' row takes them to a MVC with a datepicker setup (the parent passes data to the child in the process). Once this date picker (or other piece of data) has been selected, how do I pass the data back? Heres some code of the setup if it helps:
/* following is inside didSelectRowAtIndexPath of parent in navigation stack */
if (row == 1) {
DateViewController *datevc = [[DateViewController alloc] init];
datevc.selectedDate = [self dateToEnter];
[self.navigationController pushViewController:datevc animated:YES;
[datevc release];
}
DateViewController.h
#import <UIKit/UIKit.h>
@interface EnterProcedureDateViewController : UIViewController {
IBOutlet UIDatePicker *datePicker;
NSDate *selectedDate;
}
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
@property (nonatomic, retain) NSDate *selectedDate;
-(IBAction)selectButtonPressed:(id)sender;
@end
DateViewController.m
#import "DateViewController.h"
@implementation EnterProcedureDateViewController
@synthesize datePicker;
@synthesize selectedDate;
-(IBAction)selectButtonPressed:(id)sender {
/* how do I pass the date pickers date back to the ivar dateToEnter of parent?? */
[self.navigationController popViewControllerAnimated:YES];
}
-(void)viewWillAppear:(BOOL)animated {
if (selectedDate == nil) {
datePicker.date = [NSDate date];
} else {
datePicker.date = selectedDate;
}
[super viewWillAppear:animated];
}
...
@end
Thanks in advance as always
Andy