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 as Xib Case 5 2. Create 6 3 with storyboard. 7 4 is created with the specified xib. There is a xib case with the same name 8 5. Case of removing controll with the same name 9 6.LOADVEIW10*/ 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]; - + /*20//1. First way: No xib and STORYBOARD21//(if there is no xib and storyboard, a blank view is automatically created as the controller's veiw) Njviewcontroller * VC = [[Njviewcontroller alloc] init];23*/ - - /*26//2. Created by storyboard 27//If created through storyboard, the arrows are created to point to the view as the Controller veiw28 29//If the controller's Loadview method is overridden, The view described in storyboard is not created as the controller's view, but instead creates a blank veiw as the controller veiw30 uistoryboard *storyboard = [Uistoryboard storyboardwith name:@ "Test" bundle:nil];31 njviewcontroller *VC = [Storyboard instantiateinitialviewcontroller];32*/ - the /*35//3. With the specified Xib case created 36//If through Xib, the veiw described in Xib is created as the controller veiw37 njviewcontroller *VC = [Njviewcontroller Alloc] initwithnibname:@ "one" bundle:nil];38*/ the + /*41//4. With the same name Xib case 42//If there is a xib with the same name, the view described in the same name Xib is automatically found as the controller veiw43 njviewcontroller *VC = [[Njviewcontrol Ler Alloc] init];44*/ $ $ /*47//5. Xib case with the same name removing the Controller 48//If there is a xib with the same name, the controller will be automatically found in the Xib view as the view49 Njviewcontroller *VC = [[Njviewcontroller alloc] init];50*/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 UIWindow 4Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];5Self.window.backgroundColor =[Uicolor Whitecolor];6 7 8 //2. Create a controller 9Njviewcontroller *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 @end 6 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