Controller creation and controller view Creation

Source: Internet
Author: User

1. Create a controller

1. method 1

Fcviewcontroller * Vc = [[fcviewcontroller alloc] init];

2. method 2

// Load the uistoryboard (Note: Only the storyboard named test is loaded, and the controllers and controls in the storyboard are not created)

Uistoryboard * storyboard = [uistoryboard storyboardwithname: @ "test" Bundle: Nil];

// Create the Controller pointed by the arrow in the storyboard

Fcviewcontroller * Vc = [storyboard instantiateinitialviewcontroller];

3. Method 3

// Create a controller with a specified XIB name

Njviewcontroller * Vc = [[njviewcontroller alloc] initwithnibname: @ "one" Bundle: Nil];

 

2. Create the Controller view (in priority order). The following statements are created in priority order)

1. Create an object based on the loadview code.

-(Void) loadview {// when loadveiw is called, it indicates when the Veiw nslog (@ "loadview") of the controller is loaded; self. view = [[uiview alloc] init]; self. view. backgroundcolor = [uicolor greencolor];}

2. Create a controller based on the storyboard)

// If the loadview method of the controller is overwritten, the view described in storyboard will not be created as the view of the controller, instead, create a blank Veiw as the controller's Veiw uistoryboard * storyboard = [uistoryboard storyboardwithname: @ "test" Bundle: Nil]; njviewcontroller * Vc = [storyboard instantiateinitialviewcontroller];

3. Create an image based on the specified XIB name

// If XIB is used, Veiw described in XIB will be created as the controller's Veiw njviewcontroller * Vc = [[njviewcontroller alloc] initwithnibname: @ "one" Bundle: Nil];

4. It is created based on the XIB with the same name as the controller but with the suffix of the controller removed

// If there is an XIB with the same name as the controller removed, the view of the XIB will be automatically found as the controller's view (if the Controller name is fcviewcontroller, The XIB name with the Controller suffix is removed: fcview. XIB) njviewcontroller * Vc = [[njviewcontroller alloc] init];

5. Create an XIB instance with the same name as the controller.

// If there is an XIB with the same name as the root controller, the view described in the XIB with the same name is automatically found as the Veiw njviewcontroller * Vc = [[njviewcontroller alloc] init];
 

Note:

If the loadview method of the controller is rewritten, the system does not load the XIB with the same name and the XIB with the same name after the controller is created, but creates a blank Veiw as the view of the controller.

// (If XIB and storyboard are not available, a blank view is automatically created as the Veiw of the controller.) njviewcontroller * Vc = [[njviewcontroller alloc] init];

 

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.