Appdelegate detailed in the project

Source: Internet
Author: User

1.appdelegate.h

The template default ingest requires the use of the "class" framework, which is the UIKit.h header file, so that it is included in the program

#import <UIKit/UIKit.h>

The "class" name in the @class declaration program here is Myviewcontroller

@class Myviewcontroller;

The name of the @interface Declaration program interface Here is Myappdelegate, where NSObject indicates that its "class" conforms to the Uiapplicationdelegate protocol, then Uiapplicationdelegate, This method provides the application with critical event information about the trigger, such as when the program runs, when it is out of memory, and when important changes occur

@interface Myappdelegate:nsobject <UIApplicationDelegate> {

Defines an object for a program display window

UIWindow *window;

Join the view to control the object of the actual variable

Myviewcontroller *viewcontroller;

}

Here @property declares the properties of the program and joins the same objects specified in the previous @interface, where Nonatomic uses a single-threaded mechanism to reduce system resource usage and generates change methods and modification methods in

Property (attribute),

Then the Retain,property option indicates to the property

(property) to send a retain (Hold message),

Instead, Iboutlet indicates that the object was created in interface Builder (Storyboard).

For example, the following code displays a window control in the application.

Connect this control to the nib file and display it in Interface Builder (Storyboard)

@property (nonatomic, retain) Iboutlet UIWindow *window;

Another example is that the code shows a view control control in the application.

Connect this control to the nib file and display it in Interface Builder (Storyboard)

@property (nonatomic, retain) Iboutlet Myviewcontroller *viewcontroller;

Program end point indicating end of MyViewController.h file

@end

2. APPDELEGATE.M

The role of the methods defined in the protocol that require implementation:

1,-(void) Applicationwillresignactive: (uiapplication *) application

Description: When the application is going to be inactive, during which time the application does not receive messages or events, such as coming to the phone

2,-(void) Applicationdidbecomeactive: (uiapplication *) application

Description: When the application executes in the active state, this is exactly the opposite of the method above

3,-(void) Applicationdidenterbackground: (uiapplication *) application

Description: Called when the program is pushed to the background. So to set the background to continue running, you can set it in this function

4,-(void) Applicationwillenterforeground: (uiapplication *) application

Description: Called when the program is going back to the foreground from the background, which is exactly the opposite of the method above.

5,-(void) Applicationwillterminate: (uiapplication *) application

Description: When the program is about to exit is called, it is usually used to save the data and some cleanup work before exiting. This needs to set the key value of the uiapplicationexitsonsuspend.

6,-(void) applicationdidreceivememorywarning: (uiapplication *) application

Description: The iphone device has only limited memory, and if the application is assigned too much memory the operating system will terminate the application's operation, this method will be executed before termination, usually can be done in the memory cleanup work to prevent the program from being terminated

7,-(void) Applicationsignificanttimechange: (uiapplication*) application

Description: Executes when the system time has changed

8,-(void) applicationdidfinishlaunching: (uiapplication*) application

Description: Executes when the program is loaded

9,-(void) application: (uiapplication) Application Willchangestatusbarframe: (cgrect) Newstatusbarframe

Description: Executes when the StatusBar box is going to change

10,-(void) application: (uiapplication*) Application willchangestatusbarorientation:

(uiinterfaceorientation) newstatusbarorientation

Duration: (nstimeinterval) duration

Description: Executed when the StatusBar box direction is going to change

11,-(BOOL) Application: (uiapplication*) Application Handleopenurl: (nsurl*) URL

Description: When executing via URL

12,-(void) application: (uiapplication*) Application didchangestatusbarorientation: (uiinterfaceorientation) Oldstatusbarorientation

Description: Executes when the StatusBar box direction changes

13,-(void) application: (uiapplication*) Application Didchangesetstatusbarframe: (cgrect) Oldstatusbarframe

Description: Executes when the StatusBar box changes

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.