In the OC-proxy-Navigation controller, the value is transferred to the oc-controller.

Source: Internet
Author: User

In the OC-proxy-Navigation controller, the value is transferred to the oc-controller.

When studying UINavigationController today, there is a function for the lower-level view controller to pass values to the upper-level view controller, and the implementation of this function is the proxy

What is a higher-level view controller and a lower-level view controller,

When a view navigation controller (UINavigationController) is used to load the View Controller (UIViewController) in turn, the parent is first loaded, and then the lower-level is loaded.

When a lower-level user transmits data to a higher-level user, the user must use a proxy (delegate ),

If data is transmitted to a superior:

Define a lower-level view controller VC2

Define a protocol:

@ Protorol SendMessage <NSObject> @ en

// Protocol method:

-(Void) sendmessage (NsString *) message;

@ End

Definition

@ Interface VC2: UIViewController <SendMessage>

// Define a proxy object

@ Property (nonatomic, assign) id delegate;


Implementation:

@ Implement VC2

-(Void) initWithDelegate {

If (delegate)

[Delegate sendmessage: @ "xiao'er is married. Come on!"];

}

}





Define the upper-level view controller VC1

Definition:

@ Interface VC1: UIViewController <SendMessage>

Implementation:

@ Implement VC1

// Method for implementing the Protocol:

-(Void) sendmessage (NsString *) message {

NsLog (@ "% @", message );

}


As mentioned above, the two views are close to each other and there is no interval between the two views.


For example, it would be hard for me to distinguish,

For example, VC1 and VC2 are two big bosses. VC objects are like VC employees. In VC1, we define a delegate generic object like a small secretary of VC1,

When VC1 is loaded into the navigation controller, it is like a VC1 employee, Xiao 1, got married. VC2 employee, Xiao 2, came to congratulate him with the secret of VC2,

Xiao2 reminds the secret to remember the phone number of xiao1,

(Small 2. Small secret = Small 1 ),

Then, when VC2 is loaded into the navigation controller by I, the employee of VC2 is married, and at the wedding of the employee,

The secret called and told xiao1 to hurry up:

However, it needs to first check whether it remembers the number of small 1.

If (delegate)

[Small secret sendmessage: @ "the second party is married. Come on!"];

}

After receiving the message, xiao1 prints a message.

This print action is not implemented by a small secret, but by sending information. As for how to deal with a small 1, it is his task, and what he wants to do is to implement this method,

Small secrets are responsible for calling and small 1 is responsible for implementing. Therefore, Xiao Mi simply says no things, and Xiao 1 will do what Xiao Mi says.


The secret says: bath ····

Xiao 1 needs to complete the bath process according to Xiao Mi's instructions. As for how to wash and who to wash with, it is Xiao 1's thing.


The analogy is often inappropriate. Please forgive me ········


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.