Getting an instance of UIStoryboard programmatically
suggest changeSWIFT:
Getting an instance of UIStoryboard programmatically can be done as follows:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
where:
- name => the name of the storyboard without the extension
- bundle => the bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application.
For example, you can use the instance created above to access a certain UIViewController instantiated within that storyboard:
let viewController = storyboard.instantiateViewController(withIdentifier: "yourIdentifier")
OBJECTIVE-C:
Getting an instance of UIStoryboard in Objective-C can be done as follows:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
Example of accessing UIViewController instantiated within that storyboard:
MyViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifier"];
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents