美文网首页
IOS UIAlertController使用

IOS UIAlertController使用

作者: 秀_ba75 | 来源:发表于2017-04-12 10:01 被阅读64次

    答:废话不多说直接上代码。如下所示:

    /*

    类方法快速创建一个提示控制器 值得注意的是这个控制器有个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];

    原文:http://www.cnblogs.com/zhangguoliang1992/p/4918684.html

    相关文章

      网友评论

          本文标题:IOS UIAlertController使用

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