2.8 展示一个警告框

2.8 展示一个警告框

我们需要一个标题,消息,一个或者多个行为按钮来创建一个经典的警告框.每一个行为按钮都有一个block,该block会在用户点击该行为按钮的时候执行.
举个例子,让我们研究一个显示一个包含一个OK按钮的显示错误信息弹窗的帮助方法.当用户点击OK按钮,警告框会消失,程序将停止繁忙模式,以下是代码:

- (void)showSaveImageFailureAlertWithMessage:(NSString *)message {
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Failed to save image" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self stopBusyMode];
    }];
    [alert addAction:okAction];
    [self presentViewController:alert animated:YES completion:nil];
}

###返回到第二章目录###
###返回到书籍目录###

猜你喜欢

转载自blog.csdn.net/GikkiAres/article/details/85317432
2.8