我想知道是否可以设置一个新的根 VC?
我的应用程序通过一个 uinavigation Controller 进行初始化,该 Controller 具有作为根 VC 的 TableView 。
然后我从 TableView 运行另一个 segue 到登录窗口(模态显示)如果您随后登录,您最终会进入 red VC/帐户页面。我现在要做的是将红色 VC 设置为应用程序的新根 VC,并删除所有底层 VC。这样我就可以显示菜单按钮/图标而不是“后退”按钮
我找到了这个,但我不知道如何使用它:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let yourViewController: ViewController = storyboard.instantiateViewControllerWithIdentifier("respectiveIdentifier") as! ViewController
let navigationController = self.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([yourViewController], animated: true)
但我无法让它工作。那么可不可以让图中红色的vc作为新的root VC。
最佳答案
Swift 4.2
也许你应该试试这个
let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
let redViewController = mainStoryBoard.instantiateViewController(withIdentifier: "respectiveIdentifier") as! ViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = redViewController
关于swift - 如何设置新的 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374272/