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