How to use code to call storyboard

Source: Internet
Author: User

Switch from network:

 

1. Get a storyboard object (the uistoryboard class object ).

If you have an existing View Controller that is instantiated from the same storyboard, you can obtain the storyboard object through its storyboard attribute. To load another storyboard object, you can call the class method storyboardwithname: Bundle: Of the uistoryboard, and pass the file name and an optional bundle of the storyboard as parameters to this method.

 

2. Call the instantiateviewcontrollerwithidentifier method of the storyboard object to pass the identifier defined when you create the View Controller in interface builder to this method.

Alternatively, you can use the instantiateinitialviewcontroller method to instantiate the first view controller of the storyboard without specifying an identifier.

 

3. display the New View Controller.

====================

The following code is more clear:

====================

In the code, how does one call a scene that has been designed in storyboard? The Code is as follows:

NSString * storyboardName = @"MainStoryboard_iPhone";NSString * viewControllerID = @"ViewID";UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];MyViewController * controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];[self presentViewController:controller animated:YES completion:nil];

How to use code to call storyboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.