Home > Net >  Presenting ViewController just shows black screen
Presenting ViewController just shows black screen

Time:04-12

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)
}

CodePudding user response:

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)
}
  • Related