Swift ios set a new root view controller

前端 未结 20 868
醉话见心
醉话见心 2020-12-13 04:46

I wonder if its possible to set a new root VC?

My app gets init with a uinavigation controller that has a table view to be the root VC.

Then from the table v

20条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 04:55

    Swift 4 Answer

    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let nextViewController = storyBoard.instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
    let navigationController = UINavigationController(rootViewController: nextViewController)            
    let appdelegate = UIApplication.shared.delegate as! AppDelegate
    appdelegate.window!.rootViewController = navigationController
    

提交回复
热议问题