iphoneuiviewcontrollertransitionaddchild

addChildViewController and remove it


In my project's main ViewController, once users of the app click the "Start" button, I add the next view to the screen:

UIViewController *nextController = [[GamePlayViewController alloc] initWithNibName:@"GamePlayView" bundle:nil];
[self addChildViewController:nextController];
[self.view addSubview:nextController.view];

Now, when users want to click back to the main menu, what is the proper code to run?

I know I can transition from one viewController to another, like so:

[self transitionFromViewController:currentPageController 
                      toViewController:nextController 
                              duration:0 
                               options:UIViewAnimationOptionTransitionCurlDown
                            animations:nil 
                            completion:^(BOOL finished) { [nextController didMoveToParentViewController:self]; }];

But what if I just want to transition back to the project's main ViewController?

THANKS!


Solution

  • Why are you trying to reinvent the wheel?
    Just use a navigation controller and push the second view controller.
    Or, if it is not proper in your case to use a navigation controller, then you can open the second view controller as a modal view and dismiss it when done...