iOS Learning Note (2)--xcode6.1 Create a xib file with no storyboard Hello World app

Source: Internet
Author: User
Tags uikit

Http://www.mamicode.com/info-detail-514151.html

Since Xcode6, the default is to create storyboard instead of xib files, and as a beginner, it is important to understand how xib is loaded, so you need to create a project without storyboard

1. Create a new project

2. Select a template for only one view

Select Single View application and click Next

3. Fill in the project information

No need to select core data, after filling out the information, click Next, then click Create

4. Delete Storyboard and launchscreen.xib files

Throw storyboard and Launchscreen into the wastebasket.

5. Modify the Info.plist file

Delete info.plist files in main storyboard file base name and launch screen interface file base name two properties

6. Create a user interface view Xib file

Click Next, then save as "Helloworldview" click Create

Drag a lable from the object library and drag a button to form the following diagram

7. Modify the View controller file

Creating an association between a view and a controller, Xcode creates the ViewController.h and VIEWCONTROLLER.M files by default, so you don't have to create your own

1) Modify the file ' s Owner of the Xib view

Click File ' Owner in the list, press Command+option+3 to open the Identity Inspector, modify the class in the custom class to Viewcontroller

2) Create an export and action Method Association

Click the two circle in the middle to open the auxiliary editor

Select lable View and Control-drag to ViewController.h @interface and @end pop-up menu, follow fill in, then enter to create export

The action method that creates the button is also the selected view and the Controll key is dragged to the secondary edit area

Once the association is created, the ViewController.h code becomes:

1 #import <uikit/uikit.h>2 3 @interface viewcontroller:uiviewcontroller4 @property (weak, nonatomic) Iboutlet Uila Bel *hellolable;5-(Ibaction) Hellobutton: (UIButton *) sender;6 7 @end

Click File's Owner in the Xib list, and then press COMMAND+OPTION+6 to open Connection Inspector View the connection to the output and the action, Associating view with the View property inherited from Viewcontroller from Uiviewcontroller

The associated connection checker is as follows

3) Modify the VIEWCONTROLLER.M code

1 #import "ViewController.h" 2  3 @interface Viewcontroller () 4  5 @end 6  7 @implementation Viewcontroller 8
   9-(void) Viewdidload {ten     [super viewdidload];11     //Do any additional setup after loading the view, typically FR Om a nib.12     }14-(void) didreceivememorywarning {     [super didreceivememorywarning];17     //Dispose of an Y resources that can be recreated.18}19-(ibaction) Hellobutton: (UIButton *) Senhder {self.helloLable.frame     = CG Rectmake (Ten, +, +);     Self.helloLable.text = @ "Hello world!"; }24 @end

8. Modify the APPDELEGATE.M file

The following code already exists in the AppDelegate.h file created by Xcode by default:

1 #import <uikit/uikit.h>2 3 @interface appdelegate:uiresponder <uiapplicationdelegate>4 5 @property (Stron G, nonatomic) UIWindow *window;6 7 @end

Xcode creates the properties of the window by default for the app delegate, opens the APPDLEGATE.M file, and introduces the ViewController.h

Rewrite APPDLEGATE.M file -(BOOL) Application: (uiapplication *) application Didfinishlaunchingwithoptions: (nsdictionary *) Launchoptions method

Other code is not modified, the code is as follows

1 #import "AppDelegate.h" 2 #import "ViewController.h" 3 @interface appdelegate () 4  5 @end 6  7 @implementation Ap Pdelegate 8  9-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {One     //Override point for customization after application launch.12     //create WINDOW13     Self.window = [[UIWindow alloc] Initwithframe:[[uiscreen mainscreen] bounds]];14     //Create Viewcontroller instance viewcontroller     * Viewcontroller = [[Viewcontroller alloc] initwithnibname:@ "Helloworldview" bundle:nil];16     //Set window root View Controller 17     Self.window.rootViewController = viewcontroller;18     self.window.backgroundColor = [Uicolor whitecolor];19     [Self.window makekeyandvisible];20     return yes;21}
9. Running the program

Command+r

Beginner iOS A lot of content is not correct, please criticize the point, thank you

iOS Learning Note (2)--xcode6.1 Create a xib file with no storyboard Hello World app

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.