After iOS 9.0, Apple officially announced no longer or no recommendation to use Uialertview and uiactionsheet to be replaced by Uialertcontroller. It's easy to use a controller to combine the two. The following is a common method of Uialertview
#import "RootViewController.h"
@interface Rootviewcontroller ()
@end
@implementation Rootviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Create a button click on the show Bomb frame
UIButton *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 Uialertcontroller
Parameter Preferredstyle: is the Ialertcontroller style
Uialertcontrollerstylealert created out of the equivalent of Uialertview
Uialertcontrollerstyleactionsheet created out of the equivalent of Uiactionsheet
Uialertcontroller *alertcontroller = [Uialertcontroller alertcontrollerwithtitle:@ "hint" message:@ "Static" PreferredStyle: ( Uialertcontrollerstylealert)];
Create a button
Uialertaction *okaction = [uialertaction actionwithtitle:@ "OK" style: (Uialertactionstyledefault) handler:^ ( Uialertaction *action) {
NSLog (@ "Pay attention to learning");
}];
Create a button
Note 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 write
NSLog (@ "Pay attention to learning");
}];
Create a warning button
Uialertaction *structlaction = [uialertaction actionwithtitle:@ warning Style: (uialertactionstyledestructive) Handler: ^ (uialertaction *action) {
NSLog (@ "Pay attention to learning");
// }];
//
Add a button to add a button to a Uialertcontroller object
[Alertcontroller addaction:okaction];
[Alertcontroller addaction:cancelaction];
[Alertcontroller addaction:structlaction];
You can add a text box only if alert
[Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {
Textfield.placeholder = @ "username";
Textfield.securetextentry = YES;
}];
Remove text
Uitextfield *text = AlertController.textFields.firstObject;
Uialertaction *action = AlertController.actions.firstObject;
The method of Uialertcontroller mode is equivalent to Uialertview show
[Self Presentviewcontroller:alertcontroller animated:yes completion:nil];
}