IOS: Reverse-pass data method when switching views second: Agent

Source: Internet
Author: User

Agent:

1, send the information of the controller set up a proxy, and customize a proxy method, used to pass the data

2. The controller receiving the information follows the protocol of the Controller that sends the information.

3. The controller that receives the information sets the agent of the controller that sends the information for itself self

4. The controller that accepts the information realizes the method in the Protocol, namely accepts the data

First, the controller is joined by modal (push), and the identifier identity of the segue is set, because this identifier is the only way to identify with the destination controller, and then the code is manipulated.

1. All Documents:

2, let Firstviewcontroller associated with their own class Viewcontroller (. h/.m)

3, let Secondviewcontroller associated with their own class Secondviewcontroller (. h/.m)

4, set the Segue identifier logo

The specific code is as follows:

Firstviewcontroller Controller-Associated Viewcontroller class

1 #import "ViewController.h"2 #import "SecondViewController.h"3 4 @interfaceViewcontroller () <SecondViewControllerDelegate>5@property (Weak, nonatomic) Iboutlet Uitextfield *Firsttextfield;6 7 @end8 9 @implementationViewcontrollerTen  One- (void) Viewdidload { A [Super Viewdidload]; - } -  the //Override this method, when the view switches, automatically call --(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender - { -     if([Segue.identifier isequaltostring:@"modal"]) +     { -         //Get Destination Controller +Secondviewcontroller *SECONDVC =Segue.destinationviewcontroller; A          at         //forward-passing data -Secondvc.information =Self.firstTextField.text; -          -         //Set up proxy -SECONDVC.Delegate=Self ; -          in     } - } to  + #pragmaMark-<secondviewcontrollerdelegate> - //Reverse Accept Information the-(void) Finishedinformation: (Secondviewcontroller *) SECONDVC andinfo: (NSString *) Infos * { $Self.firstTextField.text =infos;Panax Notoginseng } - @end

Secondviewcontroller Controller-Associated Seconviewcontroller class

1 #import "SecondViewController.h"2 3 @interfaceSecondviewcontroller ()4@property (Weak, nonatomic) Iboutlet Uitextfield *Secondtextfield;5 6 @end7 8 @implementationSecondviewcontroller9 //trigger event on returnTen-(Ibaction) returnclicked: (Uibarbuttonitem *) Sender One { A     //passing data in reverse -[Self.Delegatefinishedinformation:self Andinfo:self.secondTextField.text]; -      the     //Close modal window - [Self.presentingviewcontroller dismissviewcontrolleranimated:yes completion:nil]; -     //[self dismissviewcontrolleranimated:yes completion:nil]; - } +  -- (void) Viewdidload { + [Super Viewdidload]; A      at     //Display the text box contents (accept the data passed over) -Self.secondTextField.text =self.information; - } -  - @end

IOS: Reverse-pass data method when switching views second: Agent

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.