how to change rootviewcontroller of NavigationController?

objective-c, uinavigationcontroller

Solution

Do either

[firstViewController.navigationController setViewControllers: [NSArray arrayWithObject: secondViewController] 
                                                    animated: YES];

or

firstViewController.navigationController.viewControllers = [NSArray arrayWithObject: secondViewController];

where `firstViewController` is an instance of `FirstViewController` and `secondViewController` is an instance of `SecondViewController` classes, respectively. The latter variant is a shortcut for `setViewControllers:animated:` without animation.

Problem

I have navigationController which is presented as modalview and whose rootviewcontroller is say FirstViewController.At some point I want to change rootviewcontroller of navigationController to SecondViewController.What I did is ``` [self.navigationController initWithRootViewController:SecondViewController]; ``` I am not sure what I did is correct and whether or not FirstViewController got released?Please anyone know what is the correct way of doing this? Thanks in advance!

Original source