这很好用:
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进入根视图控制器?
但是如何实现呢?
答案 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