Attempt to present ViewController whose view is not in the windows hierarchy

前端 未结 6 1489
一整个雨季
一整个雨季 2020-12-14 13:34

I meet a strange problem: I made 2 view controllers for wich I can switch the view with code:

var currentViewController:UIViewController=UIApplication.shared         


        
6条回答
  •  臣服心动
    2020-12-14 14:04

    Use like this

    let vc = self.view?.window?.rootViewController
    func showController()
    {
        let ViewControllernew1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "viewController2")
    
        vc.present(ViewControllernew1, animated: true, completion: nil)
    }
    

    Maybe the issue is with the currentViewController.

提交回复
热议问题