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