when users use the app for some risky operations, the use of dialog boxes to prompt users to play a very user-friendly role. The following two types of dialogs are commonly used: Uiactionsheet and Uialertview. But after iOS8 uiactionsheet and uialertview are defined as obsolete, official documentation explains:
Uiactionsheet is deprecated. Use Uialertcontroller with a preferredstyle of Uialertcontrollerstyleactionsheet instead
Here are the basic uses of two common dialog boxes:
//First way
Create a bullet box indicator
Uiactionsheet *sheet = [[Uiactionsheet alloc] initwithtitle:@ "Are you sure you want to cancel?" "Delegate:self cancelbuttontitle:@" Cancel "destructivebuttontitle:@" OK "otherbuttontitles:nil, nil];
Bullet Box Tips
[Sheet Showinview:nil];
Use Uiactionsheet's proxy method for related operations
Proxy methods for #pragma mark-actionsheet
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) Buttonindex;
{
if (Buttonindex = = 0) {//click OK button
//write code that requires relevant action
}
The second way
Create dialog box
Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:nil message:@ "Pro, are you sure you want to log off? [Preferredstyle:uialertcontrollerstyleactionsheet];
Create Cancel button
Uialertaction *cancelaction = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ ( Uialertaction *action) {
Related actions
}];
Create OK button
Uialertaction *sureaction = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledestructive handler:^ ( Uialertaction *action) {
callback method
[Self.navigationcontroller Popviewcontrolleranimated:yes];
}];
Add a button to a dialog box
[Alert addaction:cancelaction];
[Alert addaction:sureaction];
Show dialog box
[Self Presentviewcontroller:alert animated:yes completion:^{
Related actions after completion of display
}];
Third, the iOS8 after the window indicator