I created a UIViewController in my Main.storyboard with a few buttons and labels. I'm trying to switch to that view controller using self.presentViewController but it will not load the view from storyboard. It will only load a blank black screen by default. Any idea on how to load the view from what i've created in storyboard?
self.presentViewController(ResultViewController(), animated: true, completion: nil)
In your storyboard go to the Attributes inspector and set the view controller's Identifier. You can then present that view controller using the following code. [sb instantiateInitialViewController] is handy if you want to start on the scene's default view controller. James, thank you!
You need to give your viewcontroller an identifier. You do that by highlighting your view controller and then give it a identifier: You then put your identifier in StoryBoard ID. Yes!
The way you're doing this just creates a new instance of your view controller. It does not create one from the prototype you've defined in Interface Builder. Instead, you should be using this, where "SomeID" is a storyboard ID that you've assigned to your view controller in Interface Builder.
if let resultController = storyboard!.instantiateViewControllerWithIdentifier("SomeID") as? ResultViewController {
presentViewController(resultController, animated: true, completion: nil)
}
You can assign a storyboard ID to your view controller in Interface Builder's identity inspector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With