Agent troubled for a long time, have been looking at the concept of online blog found not their own! What I want is an agent process.
First name of the interface, let's call Apple! The second interface is called Banana, and the value in banana wants to be passed to Apple, which will use the proxy, can you use other values? Yes, but let's look at the surrogate value first.
Banana pass value, banana will find an agent.
I. Banana
The first step:
Defining the Proxy in Banana.h
@protocol bananadelegate <nsobject>
Declares a proxy method: The default is @require, the proxy method must be implemented, @optional, must not be implemented.
-(void) Bananadelegate: (bananaviewcontroller *) controller Bananamodel: (BananaModel * ) model;
@end
@interface bananaviewcontroller: uiviewcontroller
@property (nonatomic, strong) ID<bananadelegate> delegate;
@end
Step Two:
Return the code that is needed in Apple in BANANA.M
-(ibaction) backbuttonclicked: (ID) sender
{
Bananamodel *m = [[Bananamodel alloc] init];
Give m a value! If:
M.name = @ "Zhang San";
Determine whether the proxy method is implemented in Apple
if([self. Delegate respondstoselector:@selector(Bananadelegate:bananamodel:)])
{
[self. Delegate BananaDelegate:self bananamodel: m];
}
[self. Navigationcontroller popviewcontrolleranimated:YES];
}
Two. Apple
The first step:
@interface appleviewcontroller () <bananaDelegate>
@end
Step Two:
Set up Proxy
Controller.delegate = self;
Step Three:
Implementing Proxy methods
-(void) Bananadelegate: (bananaviewcontroller *) controller Bananamodel: (BananaModel *) model
{
This is to get the value of the coming, you finish the task you want it!
}
Just see no use, write a few more times until skilled! Then, you can understand!
iOS proxy mode