Use of the agent in OC, use of the OC agent

Source: Internet
Author: User

Use of the agent in OC, use of the OC agent

Generally, the following steps are required for proxy:

1. Develop an agreement. The protocol can be declared in. h of the delegate object, or in a separate. h. After the protocol is developed, the method that requires proxy objects is declared in the Protocol.

2. Set proxy properties. After the protocol is set, you need to set a proxy attribute for the delegate object. The proxy attribute is used to store the proxy object of the delegate object. The specific format is as follows:

@ Property (nonatomic, assign) id <*****> delegate; // ***** indicates the protocol name.

3. Specify the proxy object. Generally, in a proxy object, the proxy of the specified delegate object is itself. Example:

* **. Delegate = self; // proxy Object Name ***

4. The proxy object is subject to the commission agreement.

5. methods required to implement proxy objects in the delegate Protocol

6. Delegate the methods in the protocol for the proxy object to be executed at the right time. That is, call methods in the implemented protocol. The common format is as follows:

If ([self. delegate respondsToSelector: @ selector (method name)]) {

// If the proxy implements the method in the protocol, the proxy will execute this method.

[Self. delegate method];

}

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.