Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to use the custom container view controller api to do the switching of the controllers. The following code shows one way to do that. In this project I had a segmented control in the main view controller (the one with the container view) that switches beetween the two controllers. initialVC is the controller that's embedded in IB, and substituteVC is the one I'm switching to. The property, container, is an IBOutlet to the container view.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; self.initialVC = self.childViewControllers.lastObject; self.substituteVC = [self.storyboard instantiateViewControllerWithIdentifier:@"Substitute"]; self.currentVC = self.initialVC; } -(IBAction)switchControllers:(UISegmentedControl *)sender { switch (sender.selectedSegmentIndex) { case 0: if (self.currentVC == self.substituteVC) { [self addChildViewController:self.initialVC]; self.initialVC.view.frame = self.container.bounds; [self moveToNewController:self.initialVC]; } break; case 1: if (self.currentVC == self.initialVC) { [self addChildViewController:self.substituteVC]; self.substituteVC.view.frame = self.container.bounds; [self moveToNewController:self.substituteVC]; } break; default: break; } } -(void)moveToNewController:(UIViewController *) newController { [self.currentVC willMoveToParentViewController:nil]; [self transitionFromViewController:self.currentVC toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionFlipFromLeft animations:nil completion:^(BOOL finished) { [self.currentVC removeFromParentViewController]; [newController didMoveToParentViewController:self]; self.currentVC = newController; }]; } </code></pre> <p><strong>After Edit:</strong></p> <p>If you want to go to the new controller with no animation, you can do it like this (this substitutes for the code that I had under case 1).</p> <pre><code>[self addChildViewController:self.substituteVC]; [self.substituteVC didMoveToParentViewController:self]; self.substituteVC.view.frame = self.container.bounds; [self.container addSubview:self.substituteVC.view]; [self.currentVC removeFromParentViewController]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload