Ios-page value transfer (protocol, Singleton)

Source: Internet
Author: User

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];
}

Related Article

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.