Skip to content

Instantly share code, notes, and snippets.

@anthonycastelli
Created October 12, 2014 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonycastelli/7e8a8cdf7ac3a21e86a6 to your computer and use it in GitHub Desktop.
Save anthonycastelli/7e8a8cdf7ac3a21e86a6 to your computer and use it in GitHub Desktop.
Child View Controllers
- (void)replaceViewController:(UIViewController *)replacementViewController {
// Load the new view controller
[self addChildViewController:replacementViewController];
[replacementViewController.view setFrame:self.view.bounds];
[self.view addSubview:replacementViewController.view];
[replacementViewController didMoveToParentViewController:self];
// Get rid of the old one
[self.selectedViewController willMoveToParentViewController:nil];
[self.selectedViewController.view removeFromSuperview];
[self.selectedViewController removeFromParentViewController];
self.selectedViewController = replacementViewController;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment