美文网首页
UIAlertController的用法

UIAlertController的用法

作者: 彗星来的那一夜 | 来源:发表于2016-12-16 11:53 被阅读4次
    类方法快速创建一个提示控制器 值得注意的是这个控制器有个preferreStyle属性你可以根据这个属性来确定是使用UIAlertView 还是 UIActionSheet

        UIAlertControllerStyleActionSheet

        UIAlertControllerStyleAlert

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"显示的标题" message:@"标题的提示信息" preferredStyle:UIAlertControllerStyleAlert];

[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    NSLog(@"点击取消");

}]];

[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    NSLog(@"点击确认");

}]];

[alertController addAction:[UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

    NSLog(@"点击警告");

}]];

[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

    NSLog(@"添加一个textField就会调用 这个block");

}];

// 由于它是一个控制器 直接modal出来就好了

[self presentViewController:alertController animated:YES completion:nil];
781237-20151028210620325-1490641678.png

相关文章

网友评论

      本文标题:UIAlertController的用法

      本文链接:https://www.haomeiwen.com/subject/oesnmttx.html