Obtain the independent controller in the Storyboard and the storyboard

Source: Internet
Author: User

Obtain the independent controller in the Storyboard and the storyboard

I recently encountered a problem with the following requirements:

Requirement: a storyboard has a single controller VC (not connected). In storyboard, drag several controls to the VC and customize a class to bind the VC, ask how to obtain this VC and display the page for setting this VC in storyboard. For example:

 

1. First, you must know the storyboard. First, we will introduce three storyboard methods:

1> the following method indicates that the storyboard name is obtained from a package (generally set to nil to get it from the main package ).
+ (UIStoryboard *) storyboardWithName :( NSString *) name bundle :( NSBundle *) storyboardBundleOrNil

2> This method gets the initial controller in the storyboard.
-(Id) instantiateInitialViewController

3> This method indicates that the controller is obtained through the Controller identifier. The new version of Xcode uses the Storyboard ID to indicate the identifier of a controller.
-(Id) instantiateViewControllerWithIdentifier :( NSString *) identifier;

Well, from the above three methods, many friends should know how to obtain the independent controller in the Storyboard.

 

2. Set the identifier of the independent VC in the storyboard, that is, the Storyboard ID, to distinguish the controller in the storyboard, as shown in

 

3. Call-instantiateViewControllerWithIdentifier in storyboard in the class to obtain the independent VC

ZJDuLiController * vc = [self. storyboard instantiateViewControllerWithIdentifier: @ "DuLi"]

 

4. push or modal output VC.

[Self. navigationController pushViewController: vc animated: YES];

The final result is as follows:

Related Article

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.