I think your idea is wrong if you meant swapping UIViews of UIViewController (hope I understood your conception).
A UIViewController should have 1 designed UIView and should manage the values of that view. As you said, you can use Containers, however you should add then UIViewController with it's view, so there is an instance which manages this view. Your first UIViewController should only add/remove that ChildViewController.
So I'd advise:
Implement a category on UIViewController and add following methods:
- (void)displayContentController:(UIViewController *)content {
[self addChildViewController:content];
content.view.frame = [[UIScreen mainScreen] bounds];
[self.view addSubview:content.view];
[content didMoveToParentViewController:self];
}
- (void)hideContentController:(UIViewController *)content {
[content willMoveToParentViewController:nil];
[content.view removeFromSuperview];
[content removeFromParentViewController];
}
Create AViewController and BViewController. In AViewController call (viewDidLoad?):
BViewController *bViewController = [[BViewController alloc] init];
[self displayContentController:bViewController];
In BViewController manage the view of this controller. AViewController should only manage when to show BViewController and when to hide it.
If I misunderstood your question please comment it, I'll delete this answer.
- prepareForSegue:sender:to manage different segues based on 3rd conditions. Or don't segue but navigate to the new view controller programmatically or invoke a specific segue from the story board with- performSegueWithIdentifier:sender:- Hermann Klecker