One: Pop-up Prompt user's prompt box when login:
1. Use a third-party framework.
2. Add the following code to the login button click event:
-(Ibaction) loginbtnclicked { NSString *acount = self.acountField.text; NSString *password = self.passwordfield.text;// jump out of the login prompt [mbprogresshud showmessage:@ "Landing"];// Analog loading Qaq Feel good dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (2.0 * nsec_per_sec)), dispatch_get_ Main_queue (), ^{// Hide the login prompt box [mbprogresshud hidehud];// determine if the user account password is entered correctly, jump out of the prompt and jump to the interface if ([acount isequaltostring:@ "Zhangsan"]&&[password isequaltostring:@ "123"]) { [self performseguewithidentifier: @ "Contactsviewcontroller" sender:nil]; [Mbprogresshud showsuccess:@ "landing Success"]; } else{ [mbprogresshud showerror:@ "account password Error"];}} );
3. In-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) The sender method gives the target controller special recursion parameters
The code is as follows
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender{#warning get the Segue target controller first, but set a new CONTACTVC, Why do the properties of the Segue target controller also change? id destcontroller = Segue.destinationviewcontroller; if ([Destcontroller Iskindofclass:[contacttableviewcontroller class]]) { Contacttableviewcontroller *contactVc = Destcontroller; Contactvc.name = Self.acountField.text; }}
This code has a do not understand the place, oneself dozen #waring, temporarily do not think, later to solve it ~
4. The actual effect is as follows:
Two: Listening text login box
1. Using notification hubs, the code is as follows:
-(void) viewdidload { [super viewdidload]; self.loginBtn.enabled = no;// Notification Center listens for text changes,// set up notification hubs, set Viewer subscription notifications [[Nsnotificationcenter Defaultcenter] Addobserver:self selector: @selector (textchange) name:uitextfieldtextdidchangenotification Object:self.acountField ]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (textchange) Name: Uitextfieldtextdidchangenotification Object:self.passwordField]; }
What the controller does when it receives notification of a change in text-(void) textchange{//the login button is available only if the account and password have a length in the text login box self.loginBtn.enabled = (self.acountField.text.length >= 5 && self.passwordField.text.length >= 3);}
Actual effect:
2. You can also add an event directly to TextField, with the following code:
[Self.acountfield addtarget:self Action: @selector (TextChange) forcontrolevents:uicontroleventeditingchanged]; [Self.passwordfield addtarget:self Action: @selector (TextChange) forcontrolevents:uicontroleventeditingchanged];
You can also connect directly in the Mainstroyboard:
2016-1-5 the first full app private address Book Implementation 2: Add Prompt user's prompt box, listen to text box