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

前端 未结 6 1490
一整个雨季
一整个雨季 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:08

    Calling function in viewDidAppear helps in my case. Solution for Swift 3:

    In your Main Controller:

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
        showTutorialModally()
    }
    
    func showTutorialModally() {
        let tutorialViewController = TutorialViewController()
        tutorialViewController.modalPresentationStyle = .overCurrentContext
        present(tutorialViewController, animated: true, completion: nil)
    }
    

    In your Tutorial Controller:

    view.backgroundColor = UIColor.clear
    view.isOpaque = false
    

提交回复
热议问题