Skip to content

Instantly share code, notes, and snippets.

@fmessina
Last active February 13, 2018 09:42
Show Gist options
  • Save fmessina/90eda235c4a71f686d2862ba576c1832 to your computer and use it in GitHub Desktop.
Save fmessina/90eda235c4a71f686d2862ba576c1832 to your computer and use it in GitHub Desktop.
Adding and removing a view controller on top of another - on iOS - without using modal presentation
// GOAL
// viewControllerA
// |_ viewControllerB
UIViewController *viewControllerA = ...;
UIViewController *viewControllerB = ...;
// Adding
[viewControllerA addChildViewController:viewControllerB];
[viewControllerA.view addSubview:viewControllerB.view];
// Removing
[viewControllerB willMoveToParentViewController:nil];
[viewControllerB.view removeFromSuperview];
[viewControllerB removeFromParentViewController];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment