Notification mode realizes two TextField and modal view--ios development
Using the notification mode, the TextField between two different interfaces is realized, and the input characters are entered into the interface, and the TextField of the previous interface is transmitted.
interface switch, where the modal view is used for the time being . (Focus on the value, so there is no tangled design interface layout, ugly point everyone forgive me)
People do not look at the code looks like a lot, because I did not use Storyboard/xib, is the code implementation layout, so the notification and modal view switch code very little ~
Implementation results:
Click on the next Page button to enter the interface two:
Enter a string at TextField:
Click the Back button to return to the interface one, where there is also a string at the TextField of the interface
Code section:
Appdelegate.m
#import "AppDelegate.h" #import "ViewController1.h" @interface appdelegate ()@end @implementation appdelegate - (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) Launchoptions { Self. Window= [[UIWindowAlloc] Initwithframe:[uiscreen Mainscreen]. Bounds]; Self. Window. BackgroundColor= [UicolorWhitecolor]; [ Self. WindowMakekeyandvisible]; ViewController1 *VC1 = [[ViewController1 alloc] init]; Self. Window. Rootviewcontroller= VC1;return YES;}
Viewcontroller1.m
#import "ViewController1.h" #import "ViewController2.h" @interface ViewController1 (){Uitextfield *text1;}@end @implementation ViewController1 - (void) Viewdidload {[SuperViewdidload]; Self. View. BackgroundColor= [UicolorGreencolor];UILabel*label = [[UILabelAlloc] Initwithframe:cgrectmake ( -, -, -, -)]; Label. Text= @"Interface One"; [ Self. ViewAddsubview:label]; Text1 = [[Uitextfield alloc] Initwithframe:cgrectmake ( -, Max, -, -)]; Text1. BackgroundColor= [UicolorWhitecolor]; [ Self. ViewADDSUBVIEW:TEXT1];UIButton*button1 = [[UIButtonAlloc] Initwithframe:cgrectmake ( -, -, -, -)]; [Button1 AddTarget: SelfAction@selector(pushbuttonaction:) forcontrolevents:uicontroleventtouchupinside]; [Button1 settitle:@"Next Page"Forstate:uicontrolstatenormal]; Button1. BackgroundColor= [UicolorBlackcolor]; [ Self. ViewAddsubview:button1];//Registered observer[[NsnotificationcenterDefaultcenter] Addobserver: SelfSelector@selector(returnaction:) name:@"Chuanzhi"ObjectNil];additional setup after loading the view.}- (void) Returnaction: (nsnotification*) Text {Text1. Text= text. UserInfo[@"Returninfo"];} - (void) Pushbuttonaction: (UIButton*) btn {ViewController2 *VC2 = [[ViewController2 alloc] init]; Vc2. Modalpresentationstyle= Uimodalpresentationfullscreen;//Toggle Effect[ SelfPRESENTVIEWCONTROLLER:VC2 Animated:YESCompletion:Nil];}
Viewcontroller2.m
#import "ViewController2.h" @interface ViewController2 (){Uitextfield *text2;}@end @implementation ViewController2 - (void) Viewdidload {[SuperViewdidload]; Self. View. BackgroundColor= [UicolorBluecolor];UILabel*label = [[UILabelAlloc] Initwithframe:cgrectmake ( -, -, -, -)]; Label. Text= @"Interface II"; [ Self. ViewAddsubview:label]; Text2 = [[Uitextfield alloc] Initwithframe:cgrectmake ( -, Max, -, -)]; Text2. BackgroundColor= [UicolorWhitecolor]; [ Self. ViewADDSUBVIEW:TEXT2];UIButton*button2 = [[UIButtonAlloc] Initwithframe:cgrectmake ( -, -, -, -)]; [Button2 AddTarget: SelfAction@selector(returnbuttonaction:) forcontrolevents:uicontroleventtouchupinside]; [Button2 settitle:@"Back"Forstate:uicontrolstatenormal]; Button2. BackgroundColor= [UicolorBlackcolor]; [ Self. ViewAddsubview:button2];additional setup after loading the view.}- (void) Returnbuttonaction: (UIButton*) BTN {nsdictionary*dic = @{@"Returninfo": Self->text2. Text};nsnotification*notification = [nsnotificationnotificationwithname:@"Chuangzhi"ObjectNilUserinfo:dic]; [[NsnotificationcenterDefaultcenter] postnotification:notification]; [ SelfDismissviewcontrolleranimated:NOCompletion:Nil];}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Notification mode realizes two TextField and modal view--ios development