In the 102nd WWDC 2011 session, Apple introduced the View Controller Containment, which is the ability to create custom view controller containers, similar to UITabBarController , UINavigationController and the like.
I watched examples several times. There are a flurry of methods associated with this drawing, but it was a little difficult to figure them out accurately. I'm going to post here what I think is happening and see if the community confirms or not confirms my suspicions.
Scenario 1: moving from parent to new parent view controller
[vc willMoveToParentViewController:self]; [self addChildViewController:vc]; [self.view addSubview:vc.view]; // or something like this. [vc didMoveToParentViewController:self];
Should the first two lines occur in this order, or can they be canceled?
Scenario 2: Moving from the parent view controller to the parent view controller
[vc willMoveToParentViewController:nil]; [vc.view removeFromSuperview]; [vc removeFromParentViewController];
Also need to call [vc didMoveToParentViewController:nil] ? The examples in session 102 did not do this in this scenario, but I do not know if this was an omission or not.
Scenario 3: moving from one parent view controller to another
This is likely to happen as follows, since the logic in each controller of the parent view will be encapsulated.
Questions
My main question is this: should this work with the controller controller? Are the above mechanics correct?
Do I need to call willMoveToParentViewController before calling addChildViewController ? For me, this seems like a logical order, but is it strictly necessary?
Do I need to call didMoveToParentViewController:nil after calling removeFromParentViewController ?
ios uiviewcontroller ios5
Gregory higherley
source share