In a ViewController I have the following:
- (void)viewWillAppear:(BOOL)animated
{
DataObject *theDataObject = [self theAppDataObject];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"MMM dd, yyyy HH:mm"];
NSString *dateStr = [formatter stringFromDate:theDataObject.deadline];
NSLog(@"Logged dateStr: %@", dateStr);
[dateTimeLabel setText:dateStr];
[super viewWillAppear:animated];
}
To clarify: dateTimeLabel IS wired up in the xib file. The viewWillAppear method is explicitly called from another ViewController, and is firing, like so:
- (IBAction)setDateTimeButtonClicked:(id)sender
{
DataObject *theDataObject = [self theAppDataObject];
theDataObject.deadline = [datePicker date];
FirstMobileViewController *mobileVC = [[FirstMobileViewController alloc] init];
[mobileVC viewWillAppear:YES];
[mobileVC release];
[UIView transitionWithView:self.view.superview
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionAllowAnimatedContent
animations:^{[self.view removeFromSuperview];}
completion:NULL];
}
The viewWillAppear method is firing — the dateStr is logged by NSLog appropriately when the superview is shown again. But the dateTimeLabel never updates. Obviously, commenting the NSLog line doesn’t make a difference.
The MADDENING thing is that even though NSLog logs dateStr just fine, if I change dateStr to, say, @"Yo!" or even to a locally initialized string, then dateTimeLabel will update, no problem.
What am I missing here?
You method to add a child view controller isn’t correct. Try with the following code (with your method, when you call ViewWillAppear, think that the view of the view controller isn’t yet initialized. (you san check that with a simple hack: adding
mobileVC.view;just after the mobileVC initialization)With this method, the viewWillAppear should be called automatically.