添加和移除子视图控制器(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];

你可能感兴趣的:(iOS备忘录)