A brief introduction to Appdelegate and WinDOS content

Source: Internet
Author: User

Learning iOS for some time, but the appdelegate in the pile of methods have been not very clear is what to use, today to seriously summarize the study.

Creation of window:

After the iOS program starts, create a UIWindow, create a controller, create a view of the controller, and then add the controller's view to the UIWindow, so the controller's view is displayed on the screen. An iOS program can be displayed on the screen entirely because it has uiwindow. UIWindow is a special kind of uiview, which is equivalent to a frame, and uiview equivalent to the inside of the canvas. There is usually only one uiwindow in an app.

Implementation of proxy methods in Appdelegate:

1. When the application starts, the application launches the portal. Executes only once when the application starts. The application parameter is used to obtain the application's state, variables, etc.

 //  Program startup complete Call this method -(BOOL) application :(uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions { //  The system automatically creates a window,    You can call window directly at this point. and set some properties for window here.  //  set window's root directory  Viewcontroller *    VIEWC = [[Viewcontroller Alloc]init];    Self.window.rootViewController  = VIEWC;  //  This is a convenient way to make the main window of the object being used appear to the front of the screen.    You can also use the Hiddenuiview method to hide this window   [Self.window makekeyandvisible];  return   Yes;}  

2. The application is going to be inactive and coming into the background, during which time the application does not receive messages or events, such as a call to the phone, etc.

-(void) Applicationwillresignactive: (uiapplication *) application {   }

3. If the program supports background operation, it is called when the program is pushed to the background. So to set the background to continue to run, in this method can be set

-(void) Applicationdidenterbackground: (uiapplication *) application{}

4. Call when the program is going back to the foreground from the background

-(void) Applicationwillenterforeground: (uiapplication *) applicatio{    }

5. The application has entered the foreground and is active

-(void) Applicationdidbecomeactive: (uiapplication *) application {}

6. The program will exit is called, usually to save data and some cleanup before exiting. This needs to set the key value of the uiapplicationexitsonsuspend.

-(void) Applicationwillterminate: (uiapplication *) application {   }

Global Variables
Appdelegate can be called throughout the application, and in other pages you can get appdelegate global variables using code snippets: Appdelegate *appdelegate=[[uiapplication Sharedapplication] delegate];
Therefore, you can define variables that need to be used globally in AppDelegate.h

A brief introduction to Appdelegate and WinDOS content

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.