iOS Development UI chapter-creation of view of the controller

Source: Internet
Author: User

iOS Development UI chapter-creation of view of the controller

One, 6 ways to create a controller view

1 #import "NJAppDelegate.h"2 #import "NJViewController.h"3 /*4 1. Without the same name Xib case5 2. Create with Storyboard6 3. Create with the specified Xib case7 4. With the same name Xib situation8 5. The case of removing controll with the same name9 6.loadveiwTen  */ One @implementationnjappdelegate A  --(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions - { the     //Create UIWindow -Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; -Self.window.backgroundColor =[Uicolor Whitecolor]; -      +     /* - //1. First way: No Xib and storyboard + //(if there is no xib and storyboard, a blank view is automatically created as the controller's veiw) A Njviewcontroller *VC = [[Njviewcontroller alloc] init]; at      */ -      -     /* - //2. Creating with Storyboard - //If created through storyboard, the arrows are created to point to the veiw of the view as the controller -       in //If the Loadview method of the controller is overridden, the view described in storyboard is not created as the controller's view, but instead creates a blank veiw as the controller veiw - Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Test" bundle:nil]; to Njviewcontroller *VC = [Storyboard Instantiateinitialviewcontroller]; +      */ -      the     /* * //3. Create with the specified Xib case $ //If you pass Xib, the veiw described in Xib will be created as the veiw of the controllerPanax Notoginseng Njviewcontroller *VC = [[Njviewcontroller alloc] initwithnibname:@ "one" bundle:nil]; -      */ the      +     /* A //4. With the same name Xib situation the //If there is a xib with the same name, the view described in the same name Xib is automatically found as a controller veiw + Njviewcontroller *VC = [[Njviewcontroller alloc] init]; -      */ $      $     /* - //5. Xib case with same name removing controller - //If there is a xib with the same name removed controller, it will automatically find the view of the Xib as the controller the Njviewcontroller *VC = [[Njviewcontroller alloc] init]; -      */Wuyi      the     //6. Overriding the controller's Loadveiw method -     //If you override the controller's Loadview method, you will not be able to load create a xib with the same name minus the controller and xib with the same name, instead create a blank veiw as the controller veiw WuNjviewcontroller *VC =[[Njviewcontroller alloc] init]; -      About     //set the Controller as window's root controller $Self.window.rootViewController =VC; -     //Show Window - [Self.window makekeyandvisible]; -      A     returnYES; +}

Six different ways:

1. Without the same name Xib case
2. Create with Storyboard
3. Create with the specified Xib case
4. With the same name Xib situation
5. The case of removing controll with the same name
6.loadveiw

Second, the priority of creating the Controller view

Apple Official documents:

Third, the controller view delay loading

Description

The view of the controller is lazily loaded: reload when used

You can use the Isviewloaded method to determine whether a Uiviewcontroller view has been loaded

The controller's view is loaded and the Viewdidload method is called

1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions2 {3     //1. Create UIWindow4Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];5Self.window.backgroundColor =[Uicolor Whitecolor];6     7     8     //2. Create a controller9Njviewcontroller *VC =[[Njviewcontroller alloc] init];Ten      One     //In fact, it is a two-step operation, first call the Loadview method, create the controller's veiw, and then set the controller's view color is purple, that is, the color of the last time to overwrite the previous color AVc.view.backgroundColor =[Uicolor Purplecolor]; -      -     //3. Set the Controller as window's root controller theSelf.window.rootViewController =VC; -      -     //4. Display window (the controller's veiw is used in this line) - [Self.window makekeyandvisible]; +      -     returnYES; +}

In the host controller file:

1 #import "NJViewController.h"2 3 @interfaceNjviewcontroller ()4 5 @end6 7 @implementationNjviewcontroller8 9 //Loadview is called when the controller needs to display the view of the controller.Ten //You can create a view to the controller in the Loadview method One //This method is typically used to customize the view of the controller A- (void) Loadview - { -     //when to call Loadveiw will mean when to load the controller's veiw theNSLog (@"Loadview"); -      -Self.view =[[UIView alloc] init]; -Self.view.backgroundColor =[Uicolor Greencolor]; + } -  +- (void) Viewdidload A { at [Super Viewdidload]; -NSLog (@"Viewdidload"); - } - @end

iOS Development UI chapter-creation of view of the controller

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.