The traditional Alertview
- (void)alertView{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"你的操作时非法的,您要继续吗" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定"nil]; alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alert show];}
The traditional Actionsheet
- (void)actionSheet{ UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"警告:你的操作时非法的,您要继续吗" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"关闭"nil]; [sheet showInView:self.view]; }
Uialertcontroller = = Uialertview + uiactionsheet
- (void) alertcontroller{//Dangerous actions: Frame Reminders //1.UIAlertView //2.UIActionSheet //iOS8 start: Uialertcontroller = = Uialertview + UiactionsheetUialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@"Warning"message:@"Your operation is illegal, do you want to continue?"Preferredstyle:uialertcontrollerstylealert];//Add button__Weaktypeof (Alert) Weakalert = alert; [Alert Addaction:[uialertaction actionwithtitle:@"OK"Style:uialertactionstyledestructive handler:^ (uialertaction *action) {NSLog(@"Clicked OK button--%@-%@", [Weakalert. Textfields. FirstobjectText], [Weakalert. Textfields. LastobjectText]); }]]; [Alert Addaction:[uialertaction actionwithtitle:@"Cancel"Style:uialertactionstylecancel handler:^ (uialertaction *action) {NSLog(@"Click the Cancel button"); }]]; [Alert Addaction:[uialertaction actionwithtitle:@"Other"Style:uialertactionstyledefault handler:^ (uialertaction *action) {NSLog(@"Click on the other button"); }]];//Add text box[Alert addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {TextField. TextColor= [UicolorRedcolor]; TextField. Text= @"123"; [TextField AddTarget: SelfAction@selector(Usernamedidchange:) forcontrolevents:uicontroleventeditingchanged];//[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (usernamedidchange:) name:uitextfie Ldtextdidchangenotification Object:textfield];}]; [Alert addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {TextField. Securetextentry=YES; TextField. Text= @"123"; }]; [ SelfPresentviewcontroller:alert Animated:YESCompletion:Nil];} - (void) Usernamedidchange: (Uitextfield *) username{NSLog(@"%@", username. Text);}
Other operations
- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) Event {Uialertcontroller *alert = [Uialertcontroller alertControll erwithtitle:@"Warning"message:@"Your operation is illegal, do you want to continue?"Preferredstyle:uialertcontrollerstyleactionsheet];//Set PopOver point to itemAlert. Popoverpresentationcontroller. Barbuttonitem= Self. Navigationitem. Leftbarbuttonitem;//Add button[Alert Addaction:[uialertaction actionwithtitle:@"OK"Style:uialertactionstyledestructive handler:^ (uialertaction *action) {NSLog(@"Click OK button"); }]]; [Alert Addaction:[uialertaction actionwithtitle:@"Cancel"Style:uialertactionstylecancel handler:^ (uialertaction *action) {NSLog(@"Click the Cancel button"); }]]; [ SelfPresentviewcontroller:alert Animated:YESCompletion:Nil];}//Uialertcontrollerstyleactionsheet Use note//1. Cannot have a text box//2. In the ipad, you must use the form of popover to show//Text fields can is added to an alert controller of style Uialertcontrollerstylealert//Can only add text boxes on Uialertcontrollerstylealert-style view
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS Development-Uialertcontroller Bullet box Reminders