First, define two interfaces ()
Interface 1:
Interface 2:
Implemented through Delegate: (the first class delegates some of its events to the ViewDelegate class to complete, and the second class operates on this proxy, that is, it assigns it a value, in this way, the first class can obtain the value through the proxy)
First, define a proxy class:
Define your own name, which defines a method for passing values
@ Protocol ViewDelegate-(void) passValue :( NSString *) value; // Method for passing values @ end
Usage:
// In the first Interface Class: # import "ViewDelegate. h "// import the prepared proxy class @ interface ViewController: UIViewController <ViewDelegate> // In. in the m file, write the following redirection method:-(void) Next {NextViewController * next = [[NextViewController alloc] initWithNibName: @ "NextViewController" bundle: [NSBundle mainBundle]; // initialize next interface. delegate = self; // it is most important to pass the self in this class to the delegate/* of the NextViewController class, delegate is the NSObject <ViewDelegate> * delegate; @ property (nonatomic, assign) NSObject <ViewDelegate> * delegate; defined by NectViewController. the delegate = self; statement is like initializing the delegate in the second class. It also makes the two classes connected through the proxy class, in the second class, you can use the delegate proxy class object to call its own method for value assignment (when the previous page is returned)-(void) back // click the back method {[delegate passValue: self. nameText. text]; // call the proxy method [self dismissModalViewControllerAnimated: YES] through delegate, it is equivalent to the value stored in the parameters of the passValue method, and then the value passed from the second class can be obtained by implementing this method in the first class.-(void) passValue :( NSString *) value {self. nameLabel. text = value; // display the value in the label.} */[self presentModalViewController: next animated: YES];}
Source code: Click to enter the demo Download Page