Three ways to create:
1. Create through code (personal advice: Although the code is cumbersome to create, but still feel that the code is king)
2. Create with Xib:
Pros: The ability to use drag controls to describe the situation inside a view
Cons: You need to set the owning custom controller in the class attribute of file ' s owner and set the view (wired) of the controller compared to storyboard
3. Create with Storyboard
Advantage: can use drag control to describe a view inside the case, if set storyboard for Mainstoryboard, you can eliminate the code to create window, etc., the system assembly automatically generated
1 //How code is created2 3 #import "LMPAppDelegate.h"4 #import "LMPOneViewController.h"5 6 @implementationlmpappdelegate7 8-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions9 {Ten //Create Window OneSelf.window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; A //Set window color to white -Self.window.backgroundColor =[Uicolor Whitecolor]; - //Setting the window root controller theSelf.window.rootViewController =[[Lmponeviewcontroller alloc] init]; - - //Display window - [Self.window makekeyandvisible]; + - returnYES; +}
1 //Storyboard How to create2 3 #import "LMPAppDelegate.h"4 #import "LMPOneViewController.h"5 6 @implementationlmpappdelegate7 8-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions9 {Ten //Create Window OneSelf.window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; A //Set window color to white -Self.window.backgroundColor =[Uicolor Whitecolor]; - the //load storyboard,@ "One" to storyboard file name, nil defaults to [NSBundle Mainbundle] -Uistoryboard *one = [Uistoryboard storyboardwithname:@" One"Bundle:nil]; - - //get the controller that the storyboard arrow refers to + //Uiviewcontroller *VC = [one instantiateinitialviewcontroller]; - + //obtain the controller with the identifier @ "other" in the storyboard
Note: The controller that I use is the controller that comes with the system, it is best to define a controller
AUiviewcontroller *VC = [one instantiateviewcontrollerwithidentifier:@" Other"]; at - //Setting the window root controller -Self.window.rootViewController =VC; - - //Display window - [Self.window makekeyandvisible]; in - returnYES; to}
1 //xib How to create2 3 #import "LMPAppDelegate.h"4 #import "LMPOneViewController.h"5 6 @implementationlmpappdelegate7 8-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions9 {Ten //Create Window OneSelf.window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; A //Set window color to white -Self.window.backgroundColor =[Uicolor Whitecolor]; - the //load the Xib file, note what type of controller is returned by the class setting in the Xib file - //actively loading a xib file -Lmponeviewcontroller *VC = [[Lmponeviewcontroller alloc] Initwithnibname:@" Both"Bundle:nil]; - + /* - Lmponeviewcontroller *VC = [[Lmponeviewcontroller alloc] init]; + Rule successively: A The default is the first loaded with the name @ "Lmponeview" of the xib, not to find the name @ "Lmponeviewcontroller" of the Xib, at If there is no system will automatically generate a blank view - - Note: If the change is not effective because you did not uninstall the emulator software, and it is best to clean in Xcode - - */ - in //Setting the window root controller -Self.window.rootViewController =VC; to + //Display window - [Self.window makekeyandvisible]; the * returnYES; $}
How to create a controller