Custom proxy mode in iOS

Source: Internet
Author: User

custom proxy mode in iOS

Custom proxy mode is divided into 6 steps, following these 6 steps, you can complete the implementation of the agent.

1. Define the Protocol (the task that holds the agent in the agreement). We do not have a protocol for some custom layout views, and we need to add a proxy in order to meet our development needs. Then we'll define a protocol. A delegateviewdelegate protocol is defined in the DelegateView.h file of the custom view, and the protocol defaults to the required implementation method, which can be used to add optional implementations to the requirements.


1. Defining the Agreement

2. Define proxy properties, which are used to store proxy objects.


2. Defining Proxy Properties

3. Specify a proxy object for Delegateview. (Find an agent to work), for example: we define a red view (requires that you change the color of your view when clicked), and then assign it a proxy object self (because the defined view is in the View controller), the current self is the View controller class. Specifies that it is a proxy. What do you want to do?


3. Specifying proxy objects

4. The proxy class is subject to the agreement.


4. Compliance with the agreement

5. The proxy class implements the method in the protocol. This only implements a method that must be implemented,-(void) Handletouchbegan: (Delegateview *) Aview; When you start clicking on the Red View, change its own view color.


5. Proxy class implementation method in Protocol

6. The principal notifies the agent to perform the task. The principal Delegateview notifies the agent (view Controller) to perform this task.


6 The delegate notifies the agent to perform the task (this code is in the delegateview.m file)

The role of the agent: to complete the task entrusted to the party, the client has some tasks do not want to complete, but also need to implement, then the task is stored in the protocol, by the agent to complete. However, the agent does not take the initiative to perform the task, requiring the client to notify the agent.

Custom proxy mode in iOS

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.