How to insert a UIViewController view from one xib inside a view into another xib?

MyViewController.xib has an Owner Owner class installed in MyViewController (a subclass of UIViewController ) and a File Owner view connected to a UIView containing some subitems.

In the OtherViewController.xib file, the File Owner class is set to UIViewController and the Owner File is connected to an empty UIView .

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

I tried adding an instance of MyViewController to the MyViewController file, but I cannot delete it inside the view (because it is not a UIView ), and I cannot get the view associated with MyViewController in MyViewController.xib (only the view manager itself and nothing associated with it, passes it to OtherViewController.xib).

+6
ios iphone uiviewcontroller interface-builder uiview
source share
4 answers

You probably don't want to do this. Follow the directions in the View Controller Programming Guide:

Note. If you want to divide the hierarchy of views into several subareas and manage them separately, use common controller objects (custom objects descending from NSObject), instead of viewing controller objects to manage each subarea. Then use one view controller object to manage the universal controller objects.

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

UITableViewCell should not be a view for a UIViewController. It may have some kind of controller object responsible for controlling its behavior (although I suspect that this behavior is likely to be contained in the cell view itself), but this controller should not inherit from the UIViewController.

+8
source share

This has changed since some other answers have been posted - you want to take a look at the latest documentation for the UIViewController, especially in the "View view" Controllers from other view controllers " section and the " Implementation of the container view controller " class reference guide . In addition, there is iTunes video from WWDC 2012: Session 236 - The evolution of view controllers in iOS . (The video is very useful, it's not just a general overview.)

+3
source share

You can put everything in one xib. For example, just put all this in your MainWindow.xib file.

0
source share

This can be done programmatically by adding a link to the OtherViewController in MyViewController. This may be a little messy and in some ways prompts me to ask why you want to do this, but ... I believe that you know what you are doing.

A warning. Since "Other" will contain a link to "My", you will want to keep My inside Other. but Do not, I repeat, do not save "Other" inside "My", such a loop will lead to errors.

Good luck and don't forget to vote

ps, if you have a little more details, I can help you figure out the best design to avoid this kind of thing :)

0
source share

All Articles