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