IOS9 the correct way to implement text input using a hint box

Source: Internet
Author: User

I wrote a blog before, "iOS9 use the correct implementation of the prompt box," The main talk about how to use the Uialertcontroller replacement uialertview for the implementation of the prompt box. Today we are going to implement the text input in the prompt box. This feature allows users to make password confirmations and other functions.

The implementation code is as follows:

#import "SecondViewController.h" #import "AppDelegate.h" @interface Secondviewcontroller () @end @implementation  secondviewcontroller-(void) viewdidload {[Super viewdidload]; }-(ibaction) Click: (ID) Sender {uialertcontroller *alertcontroller = [Uialertcontroller alertcontrollerwithtitle:@] Prompt  "message:@" Please enter personal information "Preferredstyle:uialertcontrollerstylealert"; add OK button; [Alertcontroller addaction:[uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault handler : ^ (uialertaction * _nonnull action) {//Get 1th input box; Uitextfield *usernametextfield = AlertController.textFields.firstO        Bject;        Get the 2nd input box; Uitextfield *passwordtextfield = AlertController.textFields.lastObject;      NSLog (@ "username =%@, password =%@", usernametextfield.text,passwordtextfield.text);    }]]; add Cancel button; [Alertcontroller addaction:[uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstyledefault handler:    Nil]]; Define the first input box; [Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield *_nonnull textField) {textfield.placeholder = @ "Please enter user name";  }]; Define a second input box; [Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield * _nonnull TextField) {Textfield.pla  Ceholder = @ "Please enter password";    }];  [Self Presentviewcontroller:alertcontroller animated:true completion:nil]; } @end

The implementation results are as follows:
。


。


At present we should try to use Uialertcontroller to replace the use of Uialertview, so to get user input is not very convenient?

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS9 the correct way to implement text input using a hint box

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.