Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change rootviewcontroller of NavigationController?

Tags:

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!

like image 300
Nuzhat Zari Avatar asked Apr 19 '12 09:04

Nuzhat Zari


People also ask

How to get navigation controller root view controller?

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.

How to get current view controller in navigation controller?

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.

What is root view controller in Swift?

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.


2 Answers

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.

like image 80
Costique Avatar answered Dec 14 '22 05:12

Costique


- (void) changeRootViewControllerOFNavigationControlllerAtRuntime:(UIViewController *) viewController {       UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:viewController];      [UIApplication sharedApplication].delegate.window.rootViewController=navController;  }      
like image 22
Abhilash Khunte Avatar answered Dec 14 '22 03:12

Abhilash Khunte