以编程方式删除NavigationController

时间:2016-08-04 13:21:57

标签: ios swift

该应用程序包含多个导航控制器。 (以下示例)

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

只要ViewController1将显示,我就会使用NavigationController.view.removeFromSuperview

删除NavigationController

每当ViewController2加载时我面临的问题。我只是看到黑屏没有别的。可能是什么问题?

删除navigationController的最佳方法是什么?

2 个答案:

答案 0 :(得分:1)

黑屏只不过是UIWindow。当您删除NavigationController时,窗口没有任何NavigationController。因此,只要删除第一个NavigationController,就必须为窗口设置NavigationController。

您可以尝试这样:

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

 appDelegate.window?.rootViewController = YOUR_NAVIGATION_CONTROLLER_OBJECT;

答案 1 :(得分:0)

可能会有所帮助:

[self.window addSubview:secondNavigationController.view];
  

在窗口中添加第二个导航控制器的视图。