After iOS 9.0 Apple officially announced that it is no longer or not recommended to use Uialertview and Uiactionsheet instead of the two with the controller to combine the two together very simple and convenient the following is a common approach to Uialertview
#import"RootViewController.h"@interfaceRootviewcontroller ()@end@implementationrootviewcontroller-(void) Viewdidload {[Super Viewdidload];Create a button click to show a bullet boxUIButton *button = [UIButton Buttonwithtype: (Uibuttontypecustom)]; button. frame = CGRectMake (100,100,100,100);Add a click method to the Button [button addTarget:Self action:@selector (Actionbutton:) forControlEvents: (UIControlEventTouchUpInside)]; button. backgroundcolor = [Uicolor Bluecolor]; [Self. View Addsubview:button];}Button's click Method-(void) Actionbutton: (UIButton *) button{Initializes a single UialertcontrollerParameter Preferredstyle: is the Ialertcontroller styleUialertcontrollerstylealert created equivalent to UialertviewUialertcontrollerstyleactionsheet created equivalent to uiactionsheet uialertcontroller *alertcontroller = [UIAlertController alertcontrollerwithtitle:@"Hint" message:@"Static" Preferredstyle: (Uialertcontrollerstylealert)];Create button Uialertaction *okaction = [Uialertaction actionwithtitle:@OK style: (Uialertactionstyledefault) handler:^ (uialertaction *action) {NSLog (@"Pay attention to study"); }];Create buttonNote the Cancel button can only add one uialertaction *cancelaction = [Uialertaction actionwithtitle:@"Cancel" style: (Uialertactionstylecancel) handler:^ (uialertaction *action) {Click on the button after the method directly in here to writeNSLog (@"Pay attention to study"); }];Create a warning buttonUialertaction *structlaction = [uialertaction actionwithtitle:@ "Warning" style: (uialertactionstyledestructive) handler : ^ (uialertaction *action) {NSLog (@ "Pay attention to learning");// }];//Add a button to add a button to the Uialertcontroller object [Alertcontroller addaction:okaction]; [Alertcontroller addaction:cancelaction];//[alertcontroller Addaction:structlaction]; The text box can be added only in alert cases [Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) { TextField. placeholder = @"username"; TextField. securetextentry = YES;}]; //// Remove text //Uitextfield *text = alertController.textFields.firstObject; Uialertaction *action = AlertController.actions.firstObject; //Uialertcontroller mode is equivalent to Uialertview Show method [Selfpresentviewcontroller:alertcontroller animated: YES completion:nil];}
iOS Uialertcontroller (after iOS 9.0 instead of Uialertview and Uiactionsheet)