[IOS development] Detailed description of appdelegate in the project

Source: Internet
Author: User

1. appdelegate. h
// By default, the template introduces the program using the "class" framework, that is, the uikit. h header file, so that it is included in the program.
# Import <uikit/uikit. h>
 
// Here @ Class declares that the "class" name in the program is myviewcontroller
@ Class myviewcontroller;
 
// Here @ interface declares that the Program Interface Name Is myappdelegate, where nsobject indicates that its "class" complies with the uiapplicationdelegate protocol, and then uiapplicationdelegate, this method provides the application with information about key events that are triggered, such as when the program runs successfully, when the memory is insufficient, and when important changes occur.
@ Interface myappdelegate: nsobject <uiapplicationdelegate> {

// Define the object of a program display window
Uiwindow * window;

// Add an object to the view to control the actual Variables
Myviewcontroller * viewcontroller;
}
 
// Here, @ property declares the properties of the program and adds the same object specified in @ interface. nonatomic uses the single-thread mechanism to reduce system resource usage, and generate the change method and change method in
// Property ),
// Then retain, the property Option, indicating to the property
(Attribute) object to send a retain (retain message ),
// Iboutlet indicates that the object is created in interface Builder (storyboard.
 
// For example, the following code shows 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;
 
// For example, the Code displays a view 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 that myviewcontroller. h file is ended
@ End
2. appdelegate. m
 
The functions of the methods to be implemented as defined in the Protocol:
1.-(void) applicationwillresignactive :( uiapplication *) Application
Note: When an application is about to run in an inactive state, during this period, the application does not receive messages or events, such as calls.
2.-(void) applicationdidbecomeactive :( uiapplication *) Application
Note: When the application enters the activity status for execution, this is exactly the opposite of the method above.
3.-(void) applicationdidenterbackground :( uiapplication *) Application
Note: This API is called when a 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
Note: This method is called when the program is to return to the foreground from the background.
5.-(void) applicationwillterminate :( uiapplication *) Application
Note: A program is called to exit. It is usually used to save data and clean up before exiting. You need to set the key value of uiapplicationexitsonsuspend.
6.-(void) applicationdidreceivememorywarning :( uiapplication *) Application
Note: iPhone devices only have limited memory. If too much memory is allocated to the application, the operating system will terminate the operation of the application. This method will be executed before the termination, you can usually clean up the memory here to prevent the program from being terminated.
7.-(void) applicationsignificanttimechange :( uiapplication *) Application
Description: executed when the system time changes
8.-(void) applicationdidfinishlaunching :( uiapplication *) Application
Note: It is executed after the program is loaded.
9.-(void) Application :( uiapplication) Application willchangestatusbarframe :( cgrect) newstatusbarframe
Description: This parameter is executed when the statusbar box is about to change.
10.-(void) Application :( uiapplication *) Application willchangestatusbarorientation:
(Uiinterfaceorientation) newstatusbarorientation
Duration :( nstimeinterval) Duration
Description: This parameter is executed when the orientation of the statusbar box is about to change.
11.-(bool) Application :( uiapplication *) Application handleopenurl :( nsurl *) URL
Note: When executed through a URL
12.-(void) Application :( uiapplication *) Application didchangestatusbarorientation :( uiinterfaceorientation) oldstatusbarorientation
Note: After the statusbar box direction changes, execute
13.-(void) Application :( uiapplication *) Application didchangesetstatusbarframe :( cgrect) oldstatusbarframe
Note: After the statusbar box changes, execute

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.