Proxy design mode, also known as "delegation", as the name implies is entrusted to others to do things
In the proxy mode, one party is called the principal and the other party is called the agent.
The principal and the agent are linked together through the agreement.
When the client wants to get the agent to do something, it only needs to send a proxy message to the agent
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7C/AC/wKioL1bVqoazWmZsAAD0PUxOfVM247.png "title=" screen shot 2016-03-01 pm 10.40.57.png "width=" 401 "height=" 178 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:401px;height:178px; " alt= "Wkiol1bvqoazwmzsaad0puxofvm247.png"/>
The role of the agent:
1) Passing events between objects: The child told her mother was hungry.
2) Transfer values between objects: Tell Mommy to be hungry and tell her what to eat.
Using Parameters in Proxy methods
3) Assign a value to your own property: The child tells his mother to be hungry and to get her mother's food.
Use return values in Proxy methods
Principal party: Propose Agency Agreement
@protocol amviewdelegate <NSObject> @optional-(void) View: (amview*) View detailinfowithstate: (BOOL) state; @end
2. Principal: Add proxy object Properties
@interface Amview:uiview@property (nonatomic, weak) id<amappviewdelegate> delegate;
3. Agent: Follow the Agency agreement
@interface Viewcontroller () <AMAppViewDelegate>
4. Agent: Be the agent of the principal party
View.delegate = self;
5. Agent: Implement Proxy method
-(void) View: (amview*) View detailinfowithstate: (BOOL) state{//...}
6. Principal: Invoking proxy methods through proxy properties
-(Ibaction) namebtnclicked: (ID) Sender {if (self.delegate && [self.delegate respondstoselector: @selector (Vie W:detailinfowithstate:]) {[self.delegate view:self detailinfowithstate:no]; }}
This article is from the "Teacheran" blog, make sure to keep this source http://annmeng.blog.51cto.com/3321237/1746505
iOS Development design mode agent