MyViewController.xib has File's Owner class set to MyViewController
(a subclass of UIViewController
) and File's Owner view connected to a UIView
containing some subviews.
OtherViewController.xib has File's Owner class set to UIViewController
and File's Owner view connected to an empty UIView
.
Is it possible in Interface Builder to embed MyViewController
's view inside the view in OtherViewController.xib?
I tried adding an instance of MyViewController
into OtherViewController.xib, but I can't drop it inside the view (because it's not a UIView
) and I can't get to the view that was associated with MyViewController
in MyViewController.xib (only the view controller itself, and nothing it's connected to, makes it over to OtherViewController.xib).
Here's a more step-by-step way to associate your new UIViewController and . xib. Select File's Owner under Placeholders on the left pane of IB. In the Property Inspector(right pane of IB), select the third tab and edit "Class" under "Custom Class" to be the name of your new UIViewController subclass.
To get an object from a xib file programatically you can use: [[NSBundle mainBundle] loadNibNamed:@"MyXibName" owner:self options:nil] which returns an array of the top level objects in the 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With