Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set root view for UINavigationController

I seem to have forgotten how to change the root view for a UINavigationController

I have this code:

[window addSubview:navController.view];

but where do i set (preferably through interface builder) the root view please?

like image 563
Lilz Avatar asked Feb 10 '26 22:02

Lilz


2 Answers

UINavigationController has a viewControllers property, which is a NSArray and is not read-only, so it can be replaced.

From Apple's UINavigationController reference

Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.

So go ahead and create a NSArray with your root view controller and set UINavigationController.viewControllers to that array.

like image 74
defvol Avatar answered Feb 13 '26 10:02

defvol


See this article :

Changing a UINavigationController’s Root View Controller

like image 32
Christophe Debove Avatar answered Feb 13 '26 10:02

Christophe Debove