iPhone how to add a view controller's view to another view controller's view?
ios, iphone, objective-c, uiview, uiviewcontroller
Solution
You need to create a Container View Controller. While iOS 5 explicitly supports container controllers, you can create container controllers in previous versions. All iOS 5 does is do some automatic forwarding of rotation/appearance events (optional...and personally I find them annoying, sending the events before I'm ready) and give you some extra methods to use in your implementation. The real issue in creating a Container View Controller is sending all the appropriate events to the sub-controllers and making sure you manage your controllers in a way that is consistent with Apple's implementation. Otherwise, you'll get odd behavior in your sub-controllers. You really need to make sure you fully understand how view controllers work in their entirety before you do this. I recommend reading the following:
Here's some links to info: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html -Scroll down to: Implementing a Container View Controller
Also here for the view controller life cycle, which will help you figure out which calls need to be made in which order: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10-SW1
I do recommend reading the entire View Controller Programming Guide....you can gleam a lot of information from there: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457-CH1-SW1
Problem
This has been long on my mind, and I do not really know how to properly add a view that's managed by a view controller to another view controller's view. This does not work, because the view does not finish loading ``` self.messageViewController = [[PopupMessagesViewController alloc] initWithNibName:@"PopupMessagesViewController" bundle:nil]; [self.view addSubview:self.messageViewController.view]; ``` How can I add a UIView that a view controller creates from a nib to another view controller's view? How can I force such view to load before adding it?