Ios-uialertcontroller three kinds of display prompt box code

Source: Internet
Author: User

Uialertview in iOS 8 or above is outdated, the official recommended that we use Uialertcontroller instead of Uialertview, Uiactionsheet

1? Uialertcontroller Show normal alert.

-(Ibaction) Showalert: (UIButton *) Sender {//Show Prompt Box//obsolete//Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Title" message:@ "message" Delegate:self cancelbuttontitl e:@ "Cancel" otherbuttontitles:@ "OK", nil];//[alert show];uialertcontroller* alert = [Uialertcontroller alertcontrollerwithtitle:@"Title"message:@"This was an alert."Preferredstyle:uialertcontrollerstylealert]; Uialertaction* DefaultAction = [uialertaction actionwithtitle:@"OK"Style:uialertactionstyledefault Handler:^ (Uialertaction *action) {                                                              //Responding to EventsNSLog (@"action =%@", action);    }]; Uialertaction* Cancelaction = [uialertaction actionwithtitle:@"Cancel"Style:uialertactionstyledefault Handler:^ (Uialertaction *action) {                                                              //Responding to EventsNSLog (@"action =%@", action);    }];    [Alert addaction:defaultaction];    [Alert addaction:cancelaction]; [Self Presentviewcontroller:alert animated:yes completion:nil];}

2? Uialertcontroller display Alert with text input

-(Ibaction) Showlist: (UIButton *) Sender {//prompt box to add a text input boxuialertcontroller* alert = [Uialertcontroller alertcontrollerwithtitle:@"Title"message:@"This was an alert."Preferredstyle:uialertcontrollerstylealert]; Uialertaction* Okaction = [uialertaction actionwithtitle:@"OK"Style:uialertactionstyledefault Handler:^ (Uialertaction *action) {                                                              //Responding to Events//Get text information                                                               for(Uitextfield *textinchalert.textfields) {NSLog (@"Text =%@", Text.text);    }                                                          }]; Uialertaction* Cancelaction = [uialertaction actionwithtitle:@"Cancel"Style:uialertactionstylecancel Handler:^ (Uialertaction *action) {                                                             //Responding to EventsNSLog (@"action =%@", Alert.textfields);    }]; [Alert Addtextfieldwithconfigurationhandler:^ (Uitextfield *TextField) {Textfield.placeholder=@"Login";    }]; [Alert Addtextfieldwithconfigurationhandler:^ (Uitextfield *TextField) {Textfield.placeholder=@"Password"; Textfield.securetextentry=YES;        }];    [Alert addaction:okaction];    [Alert addaction:cancelaction]; [Self Presentviewcontroller:alert animated:yes completion:nil];}

3? Uialertcontroller Display Actionsheet

-(Ibaction) Showsheet: (UIButton *) Sender {//Show pop-up box list selectionuialertcontroller* alert = [Uialertcontroller alertcontrollerwithtitle:@"Title"message:@"This was an Sheet."Preferredstyle:uialertcontrollerstyleactionsheet]; Uialertaction* Cancelaction = [uialertaction actionwithtitle:@"Cancel"Style:uialertactionstylecancel Handler:^ (Uialertaction *action) {                                                              //Responding to EventsNSLog (@"action =%@", action);    }]; Uialertaction* Deleteaction = [uialertaction actionwithtitle:@"Delete"style:uialertactionstyledestructive Handler:^ (Uialertaction *action) {                                                             //Responding to EventsNSLog (@"action =%@", action);    }]; Uialertaction* Saveaction = [uialertaction actionwithtitle:@"Save"Style:uialertactionstyledefault Handler:^ (Uialertaction *action) {                                                             //Responding to EventsNSLog (@"action =%@", action);    }];    [Alert addaction:saveaction];    [Alert addaction:cancelaction];    [Alert addaction:deleteaction]; [Self Presentviewcontroller:alert animated:yes completion:nil];}

Ios-uialertcontroller three kinds of display prompt box code

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.