IOS Delegate & Protocal

Source: Internet
Author: User

To summarize:

Delegate is a kind of coordination thought of the Division of labor between the program and the unit.

Protocal this thing can not be said alone, to be related to its two main things together, one is a delegate is usually a view, a delegate is usually a controller

It is mainly used to pre-define a protocol, can be understood as the idea of TCP/IP protocol, the service side, the client is the TCP/IP protocol specification to communicate.

Now that it's called a protocol, it must have a definite definition of what it does, the behavior, or what it is called.

What this so-called doing is predefined, called by the delegate (implemented by the entrusted person), and the definition is defined by defining the name of the action and the corresponding parameter and type.

The following is where the entrusted person follow the protocol and then implements it. The delegate can set his or her principal to be a person, that is, to set the client's reference to his own delegate attribute.

Anycontroller.delegate = self. Self in this class to implement the Protocol method.

If the principal has a specific client, it can effectively invoke the pre-defined method in the protocol.

The delegate also needs to declare the properties of the good one delegate in the header file of the class definition (@PROPERTY id<protoacalname> delegate this form).

That such an organic mechanism of cooperation came out, and these are a clear coordination between the working method is completed.

That is, both the VIEW & CONTROLLER adhere to the Protocal protocol, as if the server and the client follow the implementation of the TCP/IP protocol

//------------------------------------------------------------------------------------------------------------- ----Concolusion

Protocal is used to define expected behavior @protocal {-(void) method_name;} @end

View is used to invoke the behavior defined by Protocal, which is called [View.delegate method_name_defined_in_protoal];

The controller is used to implement the behavior defined by the Protocal, and the controller is set to the delegate of the view. The delegate property that is referenced to the controller is passed. View.delegate = self;

The collaboration between the entire program module functionality is clear, it is not the only good way, but it is a good way.

IOS Delegate & Protocal

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.