IOS Basics (22) Creating a controller

Source: Internet
Author: User

Create a Controller

1th way through the code controller

HKUIViewController.h

#import <UIKit/UIKit.h>@interface hkuiviewcontroller:uiviewcontroller@end

Hkuiviewcontroller.m

" HKUIViewController.h " @implementation Hkuiviewcontroller@end

Appdelegate.m

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions {     = [[UIWindow alloc]init];     * HKVC = [[Hkuiviewcontroller alloc]init];     = [Uicolor redcolor];     = HKVC;    [Self.window makekeyandvisible];         return YES;}

2nd way: Load the controller via storyboard.

1) Xcode Create storyboard

Storyboard, User interface, IOS, Xcode, create a new file named Test.storyboard.

2) Set Test.storyboard to initial View Controller

Check the is initial View Controller.

3) Drag a View controller into the Test.storyboard.

Set his class to Hkuiviewcontroller.

Appdelegate.m

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions {     = [[UIWindow alloc]init];        *storyboard = [Uistoryboard storyboardwithname:@ "Test"  Bundle:nil];     * HKVC =  [Storyboard Instantiateinitialviewcontroller];         = HKVC;    [Self.window makekeyandvisible];         return YES;}

The controller can also be loaded by means of a representation.

In Test.storyboard, the identity setting Storyboard ID is switch.

Appdelegate.m

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[UIWindow alloc]init]; Uistoryboard*storyboard = [Uistoryboard storyboardwithname:@"Test"Bundle:nil]; //Hkuiviewcontroller * HKVC = [Storyboard Instantiateinitialviewcontroller];Hkuiviewcontroller *HKVC = [Storyboard Instantiateviewcontrollerwithidentifier:@"Switch"]; Self.window.rootViewController=HKVC;        [Self.window makekeyandvisible]; returnYES;}

Knowledge Points:

Commond + N Create a new storyboard

IOS Basics (22) Creating 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.