text: iphone - adding view controller in navigationcontroller issue - Stack Overflow
  adding view controller in navigationcontroller issue
  @interface DiscountDetailViewController : UIViewController {
  UILabel * offerLabel;
  @property (nonatomic, retain) IBOutlet UILabel * titleLabel;
  @property (nonatomic, retain) IBOutlet UILabel * offerLabel;
  and I tried to do the following in the previous view:
  discount = [[DiscountDetailViewController alloc] initWithNibName:@"DiscountDetailViewController" bundle:nil];
  discount.titleLabel.text = temp.vendor;
  discount.offerLabel.text = temp.description;
  [self.navigationController pushViewController:discount animated:YES];
  The issue is that, discount.titleLabel.text when printed is always null... I think it's because I define the titleLabel using interface builder.. so is there a way to resolve this?
  I've hooked it up with IB as well..
  iphone objective-c share|improve this question edited Apr 19 '11 at 19:31
  Where is "temp" defined?
  It's there somewhere, when I do NSLog(@"%@", temp.vendor), it prints out just fine..
  If your outlets are properly connected then it is only because your titleLabel will not be available until your viewIsLoaded around -(void)viewDidLoad, I recommend you use an NSString property that can set the title label once view is loaded and update it when it is changed (override setter), or if you know your view is about to show try calling view first.
  //Force view to load, do not really recommend (though for some reason I am showing you how)
  [discount view];
  i don't believe the iboutlets get hooked up until the view is on screen for the first time.
  you could try setting the label after its displayed, or add another property to store the label text, then set the iboutlet label based on this new property in viewDidLoad in your DiscountDetailViewController.
  More specifically, outlets are connected when the view controller's -viewDidLoad is called, and that happens when the controller's view property is first accessed. You should usually avoid accessing that property until after -viewDidLoad in order to support lazy loading of the view, but the view may or may not end up on the screen when it's loaded.