First, the effect
Second, the realization
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *) event
{
[Self alertTest3];
}
/**
* Text dialog box
*/
-(void) alertTest3
{
1. Create Uialertcontroller
Uialertcontroller *alertcontroller = [Uialertcontroller
alertcontrollerwithtitle:@ "Text dialog box"
message:@ "Login and Password dialog box example"
Preferredstyle:uialertcontrollerstylealert];
2. Add Text dialog box
/**
Benefits:
1. You can add any of the Uitextfield objects to the dialog box
2. All Uitextfield features can be used
*/
[Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield * _nonnull TextField) {
Textfield.placeholder = @ "Login";
}];
[Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield * _nonnull TextField) {
Textfield.placeholder = @ "password";
Textfield.securetextentry = yes;//Ciphertext
}];
3. Create a Uialertaction instance
Uialertaction *okaction = [uialertaction actionwithtitle:@ "Good" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {//click the "OK" button, let the program read the value in the text box, and then do something
Uitextfield *login = AlertController.textFields.firstObject;
Uitextfield *password = AlertController.textFields.lastObject;
}];
Uialertaction *cancelaction = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ ( Uialertaction * _nonnull action) {
}];
4.UIAlertAction instance added to Alertcontroller
[Alertcontroller addaction:okaction];
[Alertcontroller addaction:cancelaction];
5. Display the View Controller
[Self Presentviewcontroller:alertcontroller animated:yes completion:^{
}];
}
Uialertcontroller class--alert Bullet Box 3 (Text dialog box)