New date not being updated


#1

I have created the date change class, however when I change the date on the date picker wheel and and go back to the detailed view, the new date is not updated to the date that was chosen from the date picker wheel.

I set the dateCreated on the item in the DateChangerController.m file but I think that it is not being “seen” by the other parts of the program, namely the DetailedView controller and is therefore not updated.

DateChangerController.h

[code]#import <UIKit/UIKit.h>

@class BNRItem;
@class DetailViewController;

@interface DateChangerController : UIViewController

{
__weak IBOutlet UIDatePicker *datePicker;
}

@property (nonatomic, strong) BNRItem *item;

@end[/code]

DateChangerController.m

[code]#import <UIKit/UIKit.h>

@class BNRItem;
@class DetailViewController;

@interface DateChangerController : UIViewController

{
__weak IBOutlet UIDatePicker *datePicker;
}

@property (nonatomic, strong) BNRItem *item;

@end[/code]

DetailViewController.h

[code]#import <UIKit/UIKit.h>

@class BNRItem;

@interface DetailViewController : UIViewController

{
__weak IBOutlet UITextField *nameField;
__weak IBOutlet UITextField *serialNumberField;
__weak IBOutlet UITextField *valueField;
// __weak IBOutlet UILabel *dateLabel;

__weak IBOutlet UIButton *changeDate;

}

  • (IBAction)changeDate:(id)sender;

@property (nonatomic, weak) IBOutlet UILabel *dateLabel;

@property (nonatomic, strong) BNRItem *item;

@end[/code]

DetailViewController.m

#import "DetailViewController.h"
#import "BNRItem.h"
#import "DateChangerController.h"

@implementation DetailViewController

@synthesize item;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[self view] setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
}

- (void)viewWillAppear:(BOOL)animated

{
    [super viewWillAppear];
    
    [nameField setText:[item itemName]];
    [serialNumberField setText:[item serialNumber]];
    [valueField setText:[NSString stringWithFormat:@"%d", [item valueInDollars]]];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
   
    [_dateLabel setText:[dateFormatter stringFromDate:[item dateCreated]]];
}

- (void)setItem:(BNRItem *)i
{
    item = i;
    [[self navigationItem] setTitle:[item itemName]];
} 

- (void)changeDate:(id)sender
{
    DateChangerController *dcc = [[DateChangerController alloc]init];
    
    [[self navigationController] pushViewController:dcc
                                           animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear];
    
    //   Clear first responder
    [[self view] endEditing:YES];
    
    
    [item setItemName:[nameField text]];
    [item setSerialNumber:[serialNumberField text]];
    [item setValueInDollars:[[valueField text] intValue]];
}

@end