I am using the containment API to create a custom container view controller
Creation of Parent View Controller in ViewDidLoad of Parent, and Setting of Child View Controllers:
[self addChildViewController:newA];
[self addChildViewController:newB];
[self addChildViewController:newC];
Now once these childVC have been added I can transition using:
[self transitionFromViewController:from
toViewController:to
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:^(BOOL b){
[to didMoveToParentViewController:self];
[from.view removeFromSuperview];
[from removeFromParentViewController];
}];
My question now is must I remove the current childVC from the parentVC to show the new VC?
completion:^(BOOL b){
[to didMoveToParentViewController:self];
[from.view removeFromSuperview];
[from removeFromParentViewController];
}
Is there a way that I can preserve those childVCs’ and simply do swipe/button-action to then navigate between these childVCs’?
So you don’t need to remove the
fromview controller’s view from the view hierarchy manually. This method handles that for you upon completion of your animation block. From the docs on this method:As a caveat to this, though, the animation block cannot be
NULLas it is in your code example (that being said, you havenil, notNULL, which doesn’t make sense since theanimationsparameter is a block, not an Objective-C object).UPDATE: Depending on your implementation,
viewDidLoadmay get called repeatedly if the memory for that view is cleaned up. AUITabBarController, for instance, generally only calls viewDidLoad upon adding your VC’s to the tab bar, and just calls viewWill/DidAppear after that. Similarly, aUINavigationControllerwon’t callviewDidLoadwhen you pop to a view controller because it’s been maintaining it in its navigation stack, but will callviewDidLoadif you pop off of a VC and then push it back on (usually). If you’re not getting the behavior you want, you can subclass this method in your container implementation.** NOTE I am removing the iphone-sdk-4.0 tag from your question, as the containment API did not become available until 5.0