Notification mode realizes two TextField and modal view--ios development

Source: Internet
Author: User

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 to implement the temporary first . (emphasis is on passing values.) So no tangled design interface layout. It's ugly, everybody forgive me.

Let's not look at the code, it looks like it's pretty much. Since I'm not using Storyboard/xib, the code implements the layout, so there's very little code for notifications and modal view switching ~

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 interface one. There is also a string at the TextField of the interface one

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];//Register 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];}

Notification mode implements two TextField and modal views--ios development

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.