views:

191

answers:

1

I have a NIB with a UIView that contains some UILabels, UIButtons etc. and a UIViewController that is loading a UITableView from a detached NIB.

I want the UITableView in the UIViewController to be positioned below my UIView, but whenever I add it in Interface Builder it takes up the whole screen, and my UIView becomes part of the UIViewController.

How can I make sure the UITableView in my UIViewController appears below the UIView?

+2  A: 

I want the UIViewController to be positioned below my UIView

What you mean is you want the UIViewController's view positioned below your existing UIView. View controllers do not show up on screen themselves.

Create a new UIView instance in your nib, position it where you want, and assign it to be the view for the view controller.

Shaggy Frog
How do I assign the new UIView to be the view for the UIViewController?
Sheehan Alam
myViewController.view = self.theViewInstanceCreatedInInterfaceBuilder;
Shaggy Frog
I have tried the above code in my parent view controller's viewDidLoad() and no luck, the UIView doesnt load with the tableview. I also tried it in IB, I set the child ViewController's view to connect to the UIView in my parent ViewController
Sheehan Alam
(1) Create UIView instance and position it in the nib (2) create a UIView IBOutlet @property in your "parent" view controller (3) hook up the UIView to this property (4) in your "parent" view controller's viewDidLoad, hook up the UIView to the "child" view controller's view @property
Shaggy Frog
I have completed Steps 1-3. In step 4, my viewDidLoad looks like this: ChildViewController *childViewController = [[ChildViewController alloc]initWithNibName:@"ChildViewController" bundle:nil];childViewController.view = self.parentViewControllerUIView;Does this look correct to you?
Sheehan Alam
When you load the view controller in that way, you're setting its view property to be the the view hierarchy from the nib. Then you overwrite that loaded nib view with the empty view. There are two solutions. The first is to not have your ChildViewController's view built with a nib; build it entirely in code instead. The second is to load the view from the nib file into a UIView* and then assign that to the view property.
Shaggy Frog
Thanks for the explanation. I am getting the following warning which could be the culprit, any thoughts?: 'View Controller (Child View)' has both its 'NIB Name' property set and its 'view' outlet connected. This configuration is not supported.
Sheehan Alam
This could be grounds for a new question. I have posted it here: http://stackoverflow.com/questions/2589582/unable-to-load-detached-nib-in-view
Sheehan Alam