IOS Proxy Transfer value

Source: Internet
Author: User

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

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.