Description: The proxy pass value is generally used in the reverse pass value.
The example of this post is: There is a and B two interface, to achieve the effect is to let a jump to B, then B has a color parameter, when B jumps to a, the color of the parameter to a, in a to use this color to change the color of their interface.
1th step: In the sender (interface B), the establishment of an agreement (declared in the. h header File)
The protocol name usually begins with the class name of this class +delegate (contains prefix)
@protocol configviewcontrollerdelegate
Declares the protocol method, usually beginning with the class name (no prefix required)
-(void) Changebgcolor: (Uicolor *) color;
2nd Step: The agent protocol in the. h file in the sender (interface B).
@interface Configviewcontroller:uiviewcontroller
ID means who can set up to be my agent
@property (nonatomic,weak) ID delegate;
ARC uses WEAK,MRC with assign
@end
3rd Step: Notify the agent (the most important step ) in the method in the sender (interface B)
This step is generally implemented in the method of jump to a in B, I created a button in B, so that the notification agent in the button jump method implemented.
if ([Self.delegate respondstoselector: @selector (changebgcolor:)]) {
Adding an If statement is to first determine whether there is a changebgcolor in interface A, and when this method is used, the proxy value is passed.
In general, a color object is instantiated first, and it is passed with this color when the value of the proxy is transferred.
[Self.delegate Changebgcolor:color];
The self here is the interface B,self.delegate is interface a (set in steps 4th and 5th)
}
4th step: Abide by the protocol in the recipient (interface a).
@interface Viewcontroller ()
5th step: Set yourself as the agent in the recipient (interface a).
Configviewcontroller *TESTVC = [[Configviewcontroller alloc] init];
Testvc.delegate = self;
6th step: Implement the method in the protocol in the recipient (interface a).
-(void) Changebgcolor: (Uicolor *) color{
Self.view.backgroundColor = color;
}
IOS Proxy Transfer value