Skip to content

Instantly share code, notes, and snippets.

@tiagobbraga
Forked from tomohisa/gist:2897676
Last active August 29, 2015 14:23
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 tiagobbraga/a8334ca852a7ffe3f30a to your computer and use it in GitHub Desktop.
Save tiagobbraga/a8334ca852a7ffe3f30a to your computer and use it in GitHub Desktop.
Add and Remove View of ViewController
// add child view
UIViewController* controller = [self.storyboard instantiateViewControllerWithIdentifier:@"test"];
[self addChildViewController:controller];
controller.view.frame = CGRectMake(0, 44, 320, 320);
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
// remove child view
UIViewController *vc = [self.childViewControllers lastObject];
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment