iOS two view pass values

Source: Internet
Author: User

Delegate
Demo using the scene, I have a A, a, two controller,a is root, jump to b,b data input returned a and carry data display to a.

A.h

#import<UIKit/UIKit.h>#import "SencondViewController.h"@interfaceFirstviewcontroller:uiviewcontroller<resultdelegate>@property (Strong, nonatomic) Iboutlet UIButton*delegatebtn, @property (Strong, nonatomic) Iboutlet Uitextfield*Result_name, @property (Strong, nonatomic) Iboutlet Uitextfield*Result_pass, @property sencondviewcontroller*second;-(Ibaction) Delegateaction: (ID) sender;-(Ibaction) Observeaction: (ID) sender;@end

a.m.

#import "FirstViewController.h"#import "SencondViewController.h"@interfaceFirstviewcontroller ()@end@implementationFirstviewcontroller@synthesizeresult_name;@synthesizeResult_pass;- (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view from its nib.}-(Ibaction) Delegateaction: (ID) Sender {Self.second=[[Sencondviewcontroller alloc]init]; Self.second.deleage=Self ; [Self.navigationcontroller pushViewController:self.second Animated:true];}-(voidResult: (NSString *) name pre: (NSString *) pass{Result_name.text=name; Result_pass.text=Pass;}@end

====================================================

B.h

#import <UIKit/UIKit.h>@protocol  resultdelegate@required-(void) result :(NSString *) name pre: (NSString *) pass; @end @interface  **_password; -(Ibaction) Save: (IDID<ResultDelegate> deleage; @end

B.m

#import "SencondViewController.h"@interfaceSencondviewcontroller ()@end@implementationSencondviewcontroller@synthesize_name;@synthesize_password;- (void) viewdidload {[Super viewdidload];}-(Ibaction) Save: (ID) Sender {NSString*txtname =[self._name text]; NSString*txtpass =[Self._password text];        [Self.deleage Result:txtname Pre:txtpass]; [Self.navigationcontroller popviewcontrolleranimated:true];}@end

iOS two view pass values

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.