I saw where others have struggled to change the dateLabel in the DetailedViewController and I am having the same issue.
@interface DatePickerController ()
// Do any additional setup after loading the view from its nib.
NSLog(@“current date is %@”, [myDatePicker date]);
// Dispose of any resources that can be recreated.
[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];
[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.
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:
and from the DatePickerController call this method:
[super viewWillDisappear]; //[[self view] endEditing:YES]; DetailViewController *dvc; dvc = [[[self navigationController] childViewControllers] objectAtIndex:1]; [dvc setNewDate:myDatePicker.date]; 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.