// // DateEdit.m // // Created by Michael Heyeck on 11/29/09. // #import "DateEdit.h" @interface DateEdit () @property (nonatomic, retain, readonly) NSDateFormatter* printFormatter; - (void)save; - (void)dismiss; @end @implementation DateEdit @synthesize object; @synthesize keyPath; @synthesize displayCell; @synthesize datePicker; - (NSDateFormatter*)printFormatter { if (!printFormatter) { printFormatter = [[NSDateFormatter alloc] init]; printFormatter.dateFormat = @"d MMMM yyyy"; } return printFormatter; } - (void)viewDidLoad { [super viewDidLoad]; // Add buttons self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismiss)] autorelease]; self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(save)] autorelease]; // Initialize control [datePicker setDate:[object valueForKeyPath:keyPath] animated:NO]; // Initialize display displayCell.textLabel.text = [self.printFormatter stringFromDate:datePicker.date]; } - (IBAction)changeDate { displayCell.textLabel.text = [self.printFormatter stringFromDate:datePicker.date]; } - (void)dealloc { [printFormatter release]; printFormatter = nil; self.object = nil; self.keyPath = nil; self.displayCell = nil; self.datePicker = nil; [super dealloc]; } #pragma mark Table view data source methods // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { return 1; } // Customize the appearance of table view cells. - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { return displayCell; } #pragma mark Table view delegate methods - (NSIndexPath*)tableView:(UITableView*)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath { return nil; } #pragma mark Extension methods - (void)save { [object setValue:datePicker.date forKeyPath:keyPath]; [self dismiss]; } - (void)dismiss { [self.navigationController popViewControllerAnimated:YES]; } @end