views:

211

answers:

2

I have a ViewController that has its own NIB. I would like to embed that NIB inside of another master NIB. How can I accomplish this in Interface Builder and how do I reference it in code?

A: 

Every NIB has an owner, which is usually the controller for the main view in that NIB. You can create an instance of your view controller quite easily in Interface Builder. Just drag out a view controller object and set the NIB property appropriately.

The problem is that you don't have a way of addressing that controller's view from within Interface Builder. You will need to write code to add the embedded view controller's view as a subview of the master view controller's view. How you actually do this is specific to your application, but it should be enough to have an outlet in the master view controller that refers to the embedded view controller.

Then, in the master view controller's viewDidLoad implementation, you add the embedded view controller's view as a subview of the master view controller's view. You'll probably have to adjust the embedded view's frame to fit properly, too.

Alex
I am unable to drag a UIViewController into my XIB. When I add a UIView I don't have the option of specifying a NIB Name.
Sheehan Alam
+1  A: 
Jordan
When I add a UIViewController to my project it takes up the entire view. Is there a way I can have it show up below some other elements that I am displaying on screen? For example, below a UILabel that I have positioned?
Sheehan Alam