The background is: one interface jumps to the second interface and then the first interface sends a notification and the second interface receives the notification and then pulls the data out.
Write the following code in ROOTVIEWCONTROLLER.M
#import "WJJRootViewController.h" #import "WJJFirstViewController.h" @interface Wjjrootviewcontroller () {Uitextfield * _textfield;} @end @implementation wjjrootviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) viewdidload{[Super Viewdidload]; Self.view.backgroundColor = [Uicolor greencolor];//do no additional setup after loading the view. _textfield = [[Uitextfield alloc] Initwithframe:cgrectmake (30, 40, 240, 30)]; _textfield.borderstyle = Uitextborderstyleroundedrect; _textfield.placeholder = @ "Please enter:"; _textfield.clearbuttonmode = Uitextfieldviewmodealways; _textfield.keyboardtype = Uikeyboardtypedefault; _textfield.returnkeytype = Uireturnkeygo; Set TextField agent to let Viewcontroller for him to put up the keyboard _textfield.delegate = self; [Self.view Addsubview:_textfield]; [SELF Createbutton];} -(void) createbutton{UIButton * button = [UIButton Buttonwithtype:uibuttontypesystem]; Button.frame = CGRectMake (20, 80, 50, 50); Button.backgroundcolor = [Uicolor blackcolor]; [Button settitle:@ "dot Me" forstate:uicontrolstatenormal]; [Button addtarget:self action: @selector (NextPage) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; }-(void) nextpage{//Create a new interface Wjjfirstviewcontroller * Firstviewcontroller = [[Wjjfirstviewcontroller alloc] init]; Set reversal style Firstviewcontroller.modaltransitionstyle = uimodaltransitionstylefliphorizontal; Move from the first interface to the second interface with animations [self Presentviewcontroller:firstviewcontroller animated:yes completion:nil]; Send a notification if the second interface receives this notification, it will be notified that the data//written in the jump interface after the second interface can be received after the jump [[Nsnotificationcenter Defaultcenter] Postnotificatio nname:@ "1523" Object:_textfield.text];}
Then in the second interface to receive this notice, the code is as follows
#import "WJJFirstViewController.h" @interface Wjjfirstviewcontroller () {UILabel * _label;} @end @implementation wjjfirstviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) viewdidload{[Super viewdidload];//do any additional setup after loading the view. _label = [[UILabel alloc] Initwithframe:cgrectmake (40, 40, 200, 50)]; _label.backgroundcolor = [Uicolor Graycolor]; [Self.view Addsubview:_label]; Get: Method is done after receiving the notification operation name: Similar channels on this channel can receive this notification [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selec Tor (get:) name:@ "1523" Object:nil];} -(void) Get: (Nsnotification *) noti{//Get notifications inside the object id obj = noti.object; NSString * str = (NSString *) obj; _label.text = str; }-(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any REsources that can is recreated.} @end
The effect is as follows
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Snail-ui learn the custom notification Nsnotification