Skip to content

Instantly share code, notes, and snippets.

@izackp
Last active August 29, 2015 13:57
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 izackp/9413365 to your computer and use it in GitHub Desktop.
Save izackp/9413365 to your computer and use it in GitHub Desktop.
A quick implementation of adding a child view controller to another view controller and specifies which view to add it to.
@interface UIViewController (AddChild)
- (void)addChildController:(UIViewController*)childController toView:(UIView*)view;
@end
@implementation UIViewController (AddChild)
- (void)addChildController:(UIViewController*)childController toView:(UIView*)view {
[childController willMoveToParentViewController:self];
childController.view.frame = view.bounds;
[view addSubview:childController.view];
[self addChildViewController:childController];
[childController didMoveToParentViewController:self];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment