////FirstViewController.h//Controller Data Transfer////Created by Wangtouwang on 15/4/15.//Copyright (c) 2015 Wangtouwang. All rights reserved.//#import<UIKit/UIKit.h>@interfaceFirstviewcontroller:uiviewcontroller@end////FIRSTVIEWCONTROLLER.M//Controller Data Transfer////Created by Wangtouwang on 15/4/15.//Copyright (c) 2015 Wangtouwang. All rights reserved.//#import "FirstViewController.h"#import "TwoViewController.h"@interfaceFirstviewcontroller () <PropagateDelegate>{UILabel*firstlable; Uitextfield*Firstfield; UIButton*firstbtn;}@end@implementationFirstviewcontroller- (void) viewdidload {[Super viewdidload]; [Self.view Setbackgroundcolor:[uicolor Blackcolor]; Firstlable= [[UILabel alloc] Initwithframe:cgrectmake ( -, -, Max, -)]; Firstlable.text=@"first page entry and exit values"; Firstlable.font=[uifont systemfontofsize:15.0]; Firstlable.textcolor=[Uicolor Whitecolor]; [Self.view addsubview:firstlable]; Firstfield= [[Uitextfield alloc] Initwithframe:cgrectmake ( -, Max, Max, -)]; Firstfield.textcolor=[Uicolor Blackcolor]; Firstfield.font=[uifont Fontwithname:@"Arial"Size14.0]; Firstfield.borderstyle=Uitextborderstyleroundedrect; Firstfield.placeholder=@"Access Value"; Firstfield.keyboardtype=Uikeyboardtypedefault; [Self.view Addsubview:firstfield]; FIRSTBTN= [[UIButton alloc] Initwithframe:cgrectmake ( -, About, Max, -)]; Firstbtn.backgroundcolor=[uicolor colorwithred:195/255.0Green -/255.0Blue -/255.0Alpha1.0]; [Firstbtn settitle:@"jump to the second page"Forstate:uicontrolstatenormal]; [Firstbtn.layer Setcornerradius:10.0];//set four fillet radii for a rectangle[firstbtn addtarget:self Action: @selector (turntwopage:) forcontrolevents:uicontroleventtouchupinside]; [Self.view ADDSUBVIEW:FIRSTBTN]; }-(void) Turntwopage: (UIButton *) btn{Twoviewcontroller*two =[[Twoviewcontroller alloc] init]; Both.Delegate=Self ; [Self.navigationcontroller pushviewcontroller:two animated:no];}-(void) Propagatetovalue: (NSString *) result{NSLog (@"Reverse pass -through value"); Firstfield.text=result;}@end
////TwoViewController.h//Controller Data Transfer////Created by Wangtouwang on 15/4/15.//Copyright (c) 2015 Wangtouwang. All rights reserved.//#import<UIKit/UIKit.h>@protocolPropagatedelegate <NSObject>@required-(void) Propagatetovalue: (NSString *) result;@end@interfaceTwoviewcontroller:uiviewcontroller@property (nonatomic,assign)ID<PropagateDelegate>Delegate;@end
////TWOVIEWCONTROLLER.M//Controller Data Transfer////Created by Wangtouwang on 15/4/15.//Copyright (c) 2015 Wangtouwang. All rights reserved.//#import "TwoViewController.h"@interfaceTwoviewcontroller () @property (nonatomic,strong) UILabel*firstlable, @property (nonatomic,strong) Uitextfield*Firstfield, @property (nonatomic,strong) UIButton*firstbtn;@end@implementationTwoviewcontroller- (void) viewdidload {[Super viewdidload]; [Self.view Setbackgroundcolor:[uicolor Blackcolor]; _firstlable= [[UILabel alloc] Initwithframe:cgrectmake ( -, -, Max, -)]; _firstlable.text=@"second page entry and exit values"; _firstlable.font=[uifont systemfontofsize:15.0]; _firstlable.textcolor=[Uicolor Whitecolor]; [Self.view addsubview:_firstlable]; _firstfield= [[Uitextfield alloc] Initwithframe:cgrectmake ( -, Max, Max, -)]; _firstfield.textcolor=[Uicolor Blackcolor]; _firstfield.font=[uifont Fontwithname:@"Arial"Size14.0]; _firstfield.borderstyle=Uitextborderstyleroundedrect; _firstfield.placeholder=@"Access Value"; _firstfield.keyboardtype=Uikeyboardtypedefault; [Self.view Addsubview:_firstfield]; _FIRSTBTN= [[UIButton alloc] Initwithframe:cgrectmake ( -, About, Max, -)]; _firstbtn.backgroundcolor=[uicolor colorwithred:195/255.0Green -/255.0Blue -/255.0Alpha1.0]; [_firstbtn settitle:@"jump to the first page"Forstate:uicontrolstatenormal]; [_firstbtn.layer Setcornerradius:10.0];//set four fillet radii for a rectangle[_firstbtn addtarget:self Action: @selector (turnfirstpage:) forcontrolevents:uicontroleventtouchupinside]; [Self.view addsubview:_firstbtn];}//Reverse pass -through value-(void) Turnfirstpage: (UIButton *) btn{[self.DelegatePropagatetovalue:_firstfield.text]; [Self.navigationcontroller Popviewcontrolleranimated:no];}@end
IOS Learning Note 2015-04-15 controller data reverse-pass value