jlstrecker jlstrecker - 1 month ago 8x
iOS Question

How to embed a UIViewController's view from one xib inside a view in another xib?

MyViewController.xib has File's Owner class set to

(a subclass of
) and File's Owner view connected to a
containing some subviews.

OtherViewController.xib has File's Owner class set to
and File's Owner view connected to an empty

Is it possible in Interface Builder to embed
's view inside the view in OtherViewController.xib?

I tried adding an instance of
into OtherViewController.xib, but I can't drop it inside the view (because it's not a
) and I can't get to the view that was associated with
in MyViewController.xib (only the view controller itself, and nothing it's connected to, makes it over to OtherViewController.xib).


You probably do not want to do this. Follow the warning in the View Controller Programming Guide:

Note: If you want to divide a view hierarchy into multiple subareas and manage each one separately, use generic controller objects (custom objects descending from NSObject) instead of view controller objects to manage each subarea. Then use a single view controller object to manage the generic controller objects.

A UIViewController subclass whose view does not fill the window will not behave as you might expect. It will not receive view controller lifecycle messages, rotation messages, or have its parentView/navigation/tabBarController properties set correctly.

A UITableViewCell should not be the view for a UIViewController. It might have some controller object responsible for managing its behavior (though I suspect this behavior can probably all be contained within the cell view itself) but that controller should not inherit from UIViewController.