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