添加和移除子视图控制器(child ViewController)

// add child viewController添加子视图

   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 viewController删除子视图

   UIViewController *vc = [self.childViewControllers lastObject];

   [vc.view removeFromSuperview];

   [vc removeFromParentViewController];

你可能感兴趣的:(添加和移除子视图控制器(child ViewController))