Delegate IOS applications and Applications

Source: Internet
Author: User

In the uiapplication. h file, we can see the uiapplication and the protocol uiapplicationdelegate.

 
@ Interface uiapplication: uiresponder <uiactionsheetdelegate>

 
{Id <uiapplicationdelegate> _ delegate; // ApplicationProgramHold the reference of the delegate object. All classes that implement the uiapplicationdelegate protocol can be used as the delegate object of the application .....}

The ID type indicates that any class that implements the uiapplicationdelegate protocol can be used as the delegate object of the uiapplication. At the same time, the instance of the uiapplication class holds the reference of the delegate object, so that when the uiapplication receives a message, you can call methods of delegate objects that have implemented protocols to delegate your tasks to others.

To put it bluntly, a class defines methods that you do not want to implement in the form of a Protocol. At the same time, this class contains an instance variable of the ID type (generic class, if another class implements this protocol, the other class can be used as the delegate object of the first class. The previous class delegates the class that you do not want to implement to the latter class. Because the first class has a reference to the second class, all instances of the first class can directly call the method of the second class instance.

At the same time, this method also defines a method for communication between two classes, that is, the two classes need to communicate, only methods defined in the Protocol can be used. (cannot other methods in the delegate class be called ?).

@ Protocol uiapplicationdelegate <nsobject> @ optional-(void) applicationdidfinishlaunching :( uiapplication *) application;-(void) Publish :( uiapplication *) application;-(void) applicationwillresignactive :( uiapplication *) application;-(void) applicationdidreceivememorywarning :( uiapplication *) application;-(void) applicationwillterminate :( uiapplication *) application;
 
...
 
@ End

 
 

 
 

 
 
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.