Last Updated: November 19, 2020
·
60.59K
· anthonylevings

Instantiate a view controller using a storyboard identifier in Xcode (iOS)

First of all give the view controller in your storyboard a Storyboard ID inside the identity inspector. Then use the following example code (ensuring the class, storyboard name and story board ID match those that you are using):

YourViewControllerClass *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];

For more details see http://sketchytech.blogspot.com/2012/11/instantiate-view-controller-using.html

Related protips:

Installing Xcode Command Line Tools on OS X Mavericks

2 Responses
Add your response

So what are the advantages to using this method of segues configured in a storyboard?

over 1 year ago ·

Thanks for the comment. To explain, this isn't triggering a storyboard segue, this is instantiating a view controller that has been created visually in interface builder (or whatever you want to call that area of Xcode now).

over 1 year ago ·