Adding and removing a child view controller

suggest change

To add a child view controller:

- (void)displayContentController:(UIViewController *)vc {
   [self addChildViewController:vc];
   // Use bounds, not frame. frame is in the parent's superview coordinates.
   vc.view.frame = self.view.bounds;
   [self.view addSubview:vc.view];
   [vc didMoveToParentViewController:self];
}

To remove a child view controller:

- (void)hideContentController:(UIViewController *)vc {
   [vc willMoveToParentViewController:nil];
   [vc.view removeFromSuperview];
   [vc removeFromParentViewController];
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents