Swift ios set a new root view controller

前端 未结 20 898
醉话见心
醉话见心 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:50

    Swift 3 AppDelegate file:::

    @IBAction func btnGoBack(_ sender: UIButton){
    
       self.goToHomeVC()
    }
    
    func goToHomeVC(){
    
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
    
        let viewController = storyboard.instantiateViewController(withIdentifier :"HomeVC") as! HomeVC
    
        let navController = UINavigationController.init(rootViewController: viewController)
    
        if let window = self.appDelegate.window, let rootViewController = window.rootViewController {
    
            var currentController = rootViewController
    
            while let presentedController = currentController.presentedViewController {
    
                currentController = presentedController
            }
    
            currentController.present(navController, animated: true, completion: nil)
        }
    }
    

提交回复
热议问题