Recently on the view of the cycle, etc. is not very clear, find the top brother article, very good, and moved over.
Original: http://www.cnblogs.com/wendingding/p/3770760.html
One, 6 ways to create a controller view
1#import"NJAppDelegate.h"2#import"NJViewController.h"3/*41. Without the same name Xib case52. Create with Storyboard63. Create with the specified Xib case74. With the same name Xib situation85. The case of removing controll with the same name96.loadveiw10*/11@implementationNjappdelegate12-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions14{15//Create UIWindowSelf.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];Self.window.backgroundColor =[Uicolor Whitecolor];1819/*201. First way: no Xib and storyboard21st(If there is no xib and storyboard, a blank view is automatically created as the controller's veiw)22Njviewcontroller *VC = [[Njviewcontroller alloc] init];23*/2425/*262. Create with Storyboard27If created through storyboard, the arrows are created to point to the veiw of the view as the controller2829If you override the controller's Loadview method, the view described in storyboard is not created as the controller's view, but instead creates a blank veiw as the controller veiw30Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Test" bundle:nil];31Njviewcontroller *VC = [Storyboard Instantiateinitialviewcontroller];32*/3334/*353. Create with the specified Xib case36If you pass Xib, the veiw described in Xib will be created as the veiw of the controller37Njviewcontroller *VC = [[Njviewcontroller alloc] initwithnibname:@ "one" bundle:nil];38*/3940/*414. With the same name Xib situation42If there is a xib with the same name, the view described in the same name Xib is automatically found as a controller veiw43Njviewcontroller *VC = [[Njviewcontroller alloc] init];44*/4546/*475. Xib case with same name removing controller48If there is a xib with the same name removed controller, it will automatically find the view of the Xib as the controller49Njviewcontroller *VC = [[Njviewcontroller alloc] init];50*/5152//6. Overriding the controller's Loadveiw method53//54 njviewcontroller *vc = [[Njviewcontroller alloc] Init]; 56 //57 self.window.rootViewController = vc 58 // show Window59 [Self.window makekeyandvisible];61 return Yes;62}
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 UIWindow4 Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];5 Self.window.backgroundColor =[Uicolor Whitecolor];678//2. Create a Controller9 Njviewcontroller *VC =[[Njviewcontroller alloc] init];1011//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 colorvc.view.backgroundColor = [Uicolor purplecolor]; 3. Set the Controller as window's root controller Self.window.rootViewController = VC; 4. Display window (veiw of controller in this line) [Self.window makekeyandvisible]; return YES; +}
In the host controller file:
1#import"NJViewController.h"23@interfaceNjviewcontroller ()45@end67@implementationNjviewcontroller89//Loadview is called when the controller needs to display the view of the controller.10//You can create a view to the controller in the Loadview method11//This method is typically used to customize the view of the controller12-(void) Loadview13{14//When to call Loadveiw will mean when to load the controller's VEIWNSLog (@"Loadview");16Self.view = [[UIView alloc] init]; 18 self.view.backgroundColor = [Uicolor greencolor];< Span style= "color: #008080;" >19 }20 21-(void) Viewdidload22 { 23 [Super Viewdidload];@ "viewdidload "); 25 }26 @end
"Go" iOS Development UI chapter-creation of view of the controller