从ViewController导航到RootViewController,主导航选项卡保持不变

时间:2017-09-09 10:24:53

标签: ios swift

这很好用:

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let innerPage: subVC = mainStoryboard.instantiateViewController(withIdentifier: "subSB") as! subVC
self.present(innerPage, animated: true, completion: nil)

这也不起作用:

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let innerPage: subVC = mainStoryboard.instantiateViewController(withIdentifier: "subSB") as! subVC
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = innerPage

除了它删除MainNavigation视图。它只显示特定视图,但没有MainNav。我认为这是因为我没有从我调用代码的ViewController进入根视图控制器?

这是它的配置方式: enter image description here

但是如何实现呢?

1 个答案:

答案 0 :(得分:1)

您正在做的是用subVC替换根视图控制器。如果你想保留mainNavigationVC并且只想更改它的' root到subVC,执行如下操作

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let innerPage: subVC = mainStoryboard.instantiateViewController(withIdentifier: "subSB") as! subVC
let mainNav: mainNavigationVC = mainNavigationVC(rootViewController: innerPage)

let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = mainNav