Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Presenting ViewController just shows black screen

I am trying to present a ViewController from a Button action. But this seems to not work as i want it to. I do not get any error but after clicking the button the screen turns black and nothing happens. The only things i could manage to find are for objective-c and i am just trying to learn Swift. I am using storyboard to design this and added the Viewcontroller in the appropriate place in the designer

Code:

@IBAction func doShow(_ sender: Any)
{
   var newWindowViewController = NewWindowViewController()
   newWindowViewController.baseItem = self.baseItem
   present(newWindowViewController, animated: false)
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to instantiate the ViewController first from your storyboard. Else it won´t contain any View and turn up black.

@IBAction func doShow(_ sender: Any)
{
    // Instantiate your ViewController here
   var newWindowViewController = storyboard?.instantiateViewController(withIdentifier: "putyourIdentifierhere")) as! NewWindowViewController
   newWindowViewController.baseItem = self.baseItem
   present(newWindowViewController, animated: false)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading