How to create a controller

Source: Internet
Author: User

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

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.