Swift 3 Attempt to present whose view is not in the window hierarchy

后端 未结 1 960
别跟我提以往
别跟我提以往 2021-01-03 03:37

This question has been asked many times but even after trying most of the possible things I am still unable to find a solution that works for me. Here is the error message.

相关标签:
1条回答
  • 2021-01-03 03:53

    I have resolved the issue the main problem is exactly what it says the view is not in the view hierarchy. In order to resolve this issue we need to set the root view controller to the current view controller using the appDelegate object. So that the view now comes in the view hierarchy and be able to present further views. Here is the code

    let initialViewController = UIStoryboard(name: "Main", bundle:nil).instantiateInitialViewController() as UIViewController
    let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
    appDelegate.window?.rootViewController = initialViewController
    

    Please read this for further information. https://stackoverflow.com/a/27608804/5123516

    0 讨论(0)
提交回复
热议问题