ios-Page Pass Value

Source: Internet
Author: User

Define a protocol on the first page, and define a protocol method to get the return value of the second page back to the first page.

#import <UIKit/UIKit.h>

#pragma mark defines a protocol for parameter passing
@protocol edelegate <NSObject>
-(void) Setreturnpwd: (NSString *) password;
@end

In the implementation file of the first page, implement the Protocol method, and set the proxy in the method of jumping to the second page.

#import "ViewController.h"
#import "MainViewController.h"

@interface Viewcontroller () <edelegate>
@end


@implementation Viewcontroller

#pragma mark Implementation Proxy method
-(void) Setreturnpwd: (NSString *) password{
Self._pwd.text=password;
}

-(void) login: (ID) sender{
Mainviewcontroller *mainview=[self.storyboard instantiateviewcontrollerwithidentifier:@ "Second"];//This is the second page, Page to jump from
mainview.delegate=self; Set up Proxy

[Self Presentviewcontroller:mainview animated:yes completion:nil];

}

Define the proxy in the header file on the second page

#import <UIKit/UIKit.h>
@protocol edelegate;


@interface Mainviewcontroller:uiviewcontroller

#pragma mark defines the proxy

@property (Nonatomic,strong) id<edelegate> delegate;

@end

In the implementation file of the second page, the proxy arguments are called in the method that returns the first page.

#import "MainViewController.h"
#import "ViewController.h"

@interface Mainviewcontroller ()
@end

@implementation Mainviewcontroller


-(void) BACKV: (ID) sender{
[Self.delegate Setreturnpwd:self._sname.text]; Invoking proxy arguments
[Self dismissviewcontrolleranimated:yes completion:nil];
}

ios-Page Pass Value

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.