Ios-page value transfer (protocol, Singleton)
Define a protocol on the first page and define a protocol method to obtain the return value from the second page to the first page.
# Import
# Pragma mark defines a protocol for parameter transfer
@ Protocol edelegate
-(Void) setReturnPwd :( NSString *) password;
@ End
In the implementation file of the first page, implement the Protocol and set the proxy in the method that redirects to the second page.
# Import "ViewController. h"
# Import "mainViewController. h"
@ Interface ViewController ()
@ End
@ Implementation ViewController
# Proxy method implemented by pragma mark
-(Void) setReturnPwd :( NSString *) password {
Self. _ pwd. text = password;
}
-(Void) login :( id) sender {
MainViewController * mainView = [self. storyboard instantiateViewControllerWithIdentifier: @ "second"]; // This is the second page to jump
MainView. delegate = self; // sets the proxy
[Self presentViewController: mainView animated: YES completion: nil];
}
Define proxy in the header file on the second page
# Import
@ Protocol edelegate;
@ Interface mainViewController: UIViewController
# Pragma mark definition proxy
@ Property (nonatomic, strong) id Delegate;
@ End
In the implementation file on the second page, return the method on the first page and call the proxy to pass the parameter.
# Import "mainViewController. h"
# Import "ViewController. h"
@ Interface mainViewController ()
@ End
@ Implementation mainViewController
-(Void) backv :( id) sender {
[Self. delegate setReturnPwd: self. _ sname. text]; // call the proxy to PASS Parameters
[Self dismissViewControllerAnimated: YES completion: nil];
}