UI Program Execution Order (Uiapplicationmain () function), custom view

Source: Internet
Author: User

General execution order of UI programs:
First enter Main, execute function uiapplicationmain (), through the function to create the Application object and specify its agent and implement listening, when the function Uiapplicationmain () will also do a jump, jump to Appdelegate
The three main functions of the Uiapplicationmain () function are:
1. Create an app's UIApplication object
2. Specify the proxy object for the application, the primary role of the agent: How to monitor how the application is running.
3. Create an event loop (Runloop: This loop is a dead loop). function: Once the user operates the application, the application responds immediately, but the user is not sure of the time of the application, so the agent must be in the listening state until the program exits.
The code is as follows:

returnUIApplicationMainnilNSStringFromClass([AppDelegateclass]));

And Appdelegate is actually an agent, it follows the Uiapplicationdelegate protocol, which is why there are many ways to start appdelegate. (Overriding the method that must be implemented in the Uiapplicationdelegate protocol)
These methods are briefly described below:

1. Tell the agent to start, the program is ready to run
The agent implements this method, the first step is to create a Window object, the second step to the window configuration properties, the third step is to set the window to the main screen and visible, if there are other views on the window, Through window rendering, you can

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.lf.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    returnYES;}

2. Tell the agent to enter inactive state (pause, stop timer time Class)

- (void)applicationwillresignactive:(UIApplication *) Application {//Sent whenThe application isAbout-to-move from active-to-inactive state. This can occur forCertain types ofTemporary interruptions (such as an incoming phone callorSMS message)or  whenThe user quits the application andIt begins the transition to the background state.//Use Thismethod to pause ongoing tasks, disable timers, andThrottle down OpenGL ES frame rates. Games should use Thismethod to pause the game.}

3. Tell the agent that the application has entered the background (storing useful data, freeing some memory, etc.)

-(void ) applicationdidenterbackground :(uiapplication *) application {/  / use this  method to release shared resources, save user data, invalidate timers, and  store Enough application state information to restore your application to its Curre NT State in  case  it    is  terminated later. // If your application supports background execution, this  method is  called instead of   Applicationwillterminate : when  the user quits.}  

4. Tell the agent to enter the foreground (cancel pause)

- (void)applicationWillEnterForeground:(UIApplication *)application {    //ofofon entering the background.}

5. Tell the agent that it has become active (cancel the suspended state of the task)

- (void)applicationDidBecomeActive:(UIApplication *)application {    //Restart any tasks that were paused (ornotwhileIfin the background, optionally refresh the user interface.}

6.

- (void)applicationWillTerminate:(UIApplication *)application {    //whenisifapplicationDidEnterBackground:.}

When the system provides a view that does not meet the actual development requirements, this time requires a developer to customize the view.
A common custom view is Uilabel and uitextfiled together.
The following is an example of a custom view with the simplest combination of Uilabel and uitextfiled:
First create a new class Ltview
In the LTVIew.h file, you first define the two properties Uilabel and Uitextfield.
LTVIew.h

@interface LTVIew : UIView@property (nonatomic,retain)UILabel *label;@property (nonatomic,retain)UITextField *textField;@end

Then rewrite the initWithFrame: method in LTVIew.h to implement the initialization of the object with Uilabel and Uitextfield.
ltview.m

#import "LTVIew.h"  @implementation ltview //Rewrite the UIView method-(ID) initWithFrame: (CGRect) frame{ Self=[SuperInitwithframe:frame];if( Self) {        [ SelfP_setup]; }return  Self;}//Finish This method and call it immediately in the initialization method of overriding the parent class-(void) p_setup{_label=[[UILabelAlloc]initwithframe:cgrectmake (0,0, Self. Frame. Size. Width/3, Self. Frame. Size. Height)]; _label. BackgroundColor=[UicolorYellowcolor]; [ SelfAddsubview:_label];    [_label release]; _textfield=[[uitextfield Alloc]initwithframe:cgrectmake (_label. Frame. Size. Width,0, Self. Frame. Size. Width*2/3, Self. Frame. Size. Height)]; _textfield. BackgroundColor=[UicolorRedcolor]; [ SelfAddsubview:_textfield]; [_textfield release];} -(void) dealloc{[_textfield release];    [_label release]; [SuperDealloc];}@end

You can then create a custom object in the APPDELEGATE.M file and assign its value to the attribute usage.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UI Program Execution Order (Uiapplicationmain () function), custom view

Related Article

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.