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!
The root view controller is simply the view controller that sits at the bottom of the navigation stack. You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers.
You can check whether a controller's view is on screen by looking at self. view. window -- that will be nil if the view is not currently in the window's hierarchy.
The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller's view as the content view of the window.
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.
- (void) changeRootViewControllerOFNavigationControlllerAtRuntime:(UIViewController *) viewController { UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:viewController]; [UIApplication sharedApplication].delegate.window.rootViewController=navController; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With