Assuming that the project is using ARC.
ContentViewController is content of UIPopoverController
- (IBAction)showPop:(UIButton *)button
{
_pressDate = [NSDate date];
ContentViewController *cvc = [[InfoViewController alloc] initWithNibName:@"ContentViewController" bundle:nil];
self.popController = [[UIPopoverController alloc] initWithContentViewController:cvc];
cvc.dateLabel.text = [_pressDate description];
[self.popController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
The code above works, no problem. But I’ve noted that if I call
cvc.dateLabel.text = [_pressDate description];
before
self.popController = [[UIPopoverController alloc] initWithContentViewController:cvc];
the label does not get an update. I just would like to understand what is the matter?
There is a thumbrule that you should not edit the UI of a ViewController before viewDidLoad is run, becuase of ther reasons
@Phillip Morrisdescribed.. Instead of setting thecvc.dateLabel.textdirectly before viewDidLoad is fired, declare a propertytextForDateLabel, and setcvc.textForDateLabel = [_pressDate description];.Then in
viewDidLoadof your ContentViewController, doself.dateLabel.text = textForDateLabel;