Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally set root view controller for a Navigation Controller

I have a navigation controller which should have a different root depending on the state of my App.

How can i model this within Interface Builder? I've dragged out a UINavigationController to my Storyboard. Now I need to make the connections to the two view controllers.

Sadly I can only set one as root view controller. Do i need to subclass the Navigation Controller and based on the state reset the root view controller?

What is the best practise for this kind of problem? It would be nice to visualize this relationship within Interface Builder.

Thanks in advance for any help.

like image 250
kukudas Avatar asked Mar 03 '26 03:03

kukudas


1 Answers

As it is the rootViewController you want to change conditionally, you could instead have two different navigationControllers, each with the one of the two different viewControllers as its rootViewController.

You could then present the appropriate navigationController based on your condition.

like image 116
JoeFryer Avatar answered Mar 05 '26 18:03

JoeFryer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!