DetailedViewController Label not updating the date


I saw where others have struggled to change the dateLabel in the DetailedViewController and I am having the same issue.


[code]#import “DatePickerController.h”
#import “BNRItem.h”

@interface DatePickerController ()


@implementation DatePickerController
@synthesize item;

  • (void)viewDidLoad
    [super viewDidLoad];
    [myDatePicker setDatePickerMode:(UIDatePickerModeDate)];
    // Do any additional setup after loading the view from its nib.
    NSLog(@“current date is %@”, [myDatePicker date]);

  • (void)didReceiveMemoryWarning
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.


[super viewWillAppear];



[super viewWillDisappear];
//[[self view] endEditing:YES];

[item setDateCreated:[myDatePicker date]];

NSLog(@"changed date is %@", [myDatePicker date]);


Like we did with the DetailedViewController and the ItemsViewController on the VIewWillDisappear method we set the values of the text in the BNRItem, i did the same here as you can see in the code above.

Then when the DetailedViewController class is the view, its ViewWIllAppear method should have the correct date that you have changed.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];

[dateLabel setText:[dateFormatter stringFromDate:[item dateCreated]]];

But, yet, the label doesn’t update to the date that i had changed. It just shows the current date. Not sure what is going on here.

I even thought that i would override the setDateCreated method in BNRItem to see more closely what was going on.


-(void)setDateCreated:(NSDate *)date{ NSLog(@"setting the new date"); dateCreated = date; }

but the log message doesn’t even show up in the console. - like the method was really never called.

I overrode one of the other setter methods in BNRItem that gets called in DetailViewController and that method does return a log statement.

So the next step was to provide a setter method in DetailViewController:

-(void)setNewDate:(NSDate *)newDate{ [item setDateCreated:newDate]; }

and from the DatePickerController call this method:


[super viewWillDisappear];
//[[self view] endEditing:YES];

DetailViewController *dvc;
dvc = [[[self navigationController] childViewControllers] objectAtIndex:1];

NSLog(@"changed date is %@", [myDatePicker date]);


This seems to work. So my question is - Is how come the DetailedViewController class was able to set the date but in the DatePickerController i was not able to? Remember that the setDateCreated: method seemed to have never been called from my DatePickerController class.

It seems to me that using “objectAtIndex” to get to the controller that you want is pretty bad anyway. not only are you using a constant but you maybe have a thread of viewcontrollers and you might not know ahead of time what index you really want.

Maybe the mods can chime in here? Is there a way for the DatePickerController to communite to BNRItem to set the date instead of going through the DetailedViewController? thanks for the insight in advance.


Try NSLogging your dateLabel when you try setting it… bet you it turns up nil.