Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing NavigationController Programmatically

Tags:

ios

swift

the application contains more than one navigation controller. (example below)

NavigationController1 ----> ViewController1 ---> TabBarController --> 
NavigationController2 ----> ViewController2

whenever ViewController1 willDisappear i remove the NavigationController using NavigationController.view.removeFromSuperview

the problem im facing whenever ViewController2 loads. i just see a black screen nothing else. what might the problem be?

and what is the best way to remove the navigationController?

like image 872
Ali Alebrahim Avatar asked Sep 17 '25 10:09

Ali Alebrahim


1 Answers

The black screen is nothing but UIWindow. When you are removing NavigationController , the windows doesn't have any NavigationController. So you will have to set NavigationController for window as soon as you remove your first NavigationController.

You can try like this:

 let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

 appDelegate.window?.rootViewController = YOUR_NAVIGATION_CONTROLLER_OBJECT;
like image 188
Vishal Sonawane Avatar answered Sep 20 '25 00:09

Vishal Sonawane