The instantiateViewControllerWithIdentifier:
method requires that the view controller I pass have an identifier. I went to my storyboard and clicked on my view controller, but I see no option to set the identifier. Where exactly do I find this option?
In the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.
A storyboard ID does exactly what the name implies: it identifies. Just that it identifies a view controller in a storyboard file. It is how the storyboard knows which view controller is which.
In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .
As the Image suggests! Hope it helps!
Then to use it you call:
[self.storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerID"];
Updated for XCode 8 and Swift 3.
instantiateViewControllerWithIdentifier
is now instantiateViewController(withIdentifier:).
Setting the storyboard ID:
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