'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)
}
Solution 1:[1]
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)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
