views:

478

answers:

1

I have two NIB's

ParentViewController.xib
ChildViewController.xib

ParentViewController.xib contains a UIView and a UIViewController. ChildViewController.xib contains a UIButton

I want ChildViewController.xib to load in the ParentViewController.xib's UIView

I have done the following:

  1. Created @property for UIView in ParentViewController
  2. Connected File's Owner to UIView in ParentViewController
  3. Set UIViewController in ParentViewController's NIB Name property to ChildViewController in Interface Builder
  4. Set ChildViewController view property to UIView in ParentViewController

I was hoping this would load ChildViewController into my UIView in ParentViewController but no luck.

I did get the following warning, which could be the culprit:

'View Controller (Child View)' has both its 'NIB Name' property set and its 'view' outlet connected. This configuration is not supported.

I also have added additional code in ParentViewController's viewDidLoad():

- (void)viewDidLoad {
    [super viewDidLoad];
    ChildViewController *childViewController = [[ChildViewController alloc]initWithNibName:@"ChildViewController" bundle:nil]; 
    childViewController.view = self.myView; 
}

Any thoughts on why ChildViewController does not load in the UIView of ParentViewController?

+2  A: 

Try this

[self.myview addSubview: childViewController.view];

instead of

childViewController.view = self.myView;

Reena