Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以编程方式删除NavigationController_Ios_Swift - Fatal编程技术网

Ios 以编程方式删除NavigationController

Ios 以编程方式删除NavigationController,ios,swift,Ios,Swift,应用程序包含多个导航控制器。(下面的例子) 每当ViewController1消失时,我使用NavigationController.view.removeFromSuperview移除NavigationController 每当ViewController2加载时,我都会遇到这个问题。我只看到一个黑屏,其他什么都看不到。问题可能是什么 移除导航控制器的最佳方法是什么?黑屏只不过是UIWindow。删除NavigationController时,windows没有任何NavigationCon

应用程序包含多个导航控制器。(下面的例子)

每当ViewController1消失时,我使用
NavigationController.view.removeFromSuperview移除NavigationController

每当ViewController2加载时,我都会遇到这个问题。我只看到一个黑屏,其他什么都看不到。问题可能是什么


移除导航控制器的最佳方法是什么?

黑屏只不过是
UIWindow
。删除NavigationController时,windows没有任何NavigationController。所以,一旦删除第一个NavigationController,就必须为Windows设置NavigationController

您可以这样尝试:

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

 appDelegate.window?.rootViewController = YOUR_NAVIGATION_CONTROLLER_OBJECT;
这可能有助于:

[self.window addSubview:secondNavigationController.view];
在窗口中添加第二个导航控制器的视图


因此,每当我移除第一个导航控制器时,我都需要在appDelegate文件中设置正确的窗口?无需从appDelegate设置。您可以为此使用AppDelegate对象。请查看我的更新答案。我在尝试添加代码时遇到此错误。我的朋友:无法分配给属性:“appDelegate”是不可变的
[self.window addSubview:secondNavigationController.view];