2016-1-5 the first full app private address Book Implementation 2: Add Prompt user's prompt box, listen to text box

Source: Internet
Author: User
Tags notification center

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

Related Article

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.