UIAlertController 警告框

switch (button.tag) {
        case 101:
        {
            /*
             按钮的类型
             UIAlertActionStyleDefault = 0,
             UIAlertActionStyleCancel,
             UIAlertActionStyleDestructive

             */
            //弹出警告框UIAlertControllerStyleAlert
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"非法入侵" preferredStyle:UIAlertControllerStyleAlert];
            //增加 按钮 行为
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                //这个block 点击取消按钮 会 回调的 代码块
                NSLog(@"alert 取消被点击");
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                NSLog(@"alert 确定被点击");
            }]];
            //只能模态跳转
            [self presentViewController:alert animated:YES completion:nil];
            
        }
            break;
        case 102:
        {
            //UIAlertControllerStyleActionSheet
            UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"分享" message:@"看这里。。。" preferredStyle:UIAlertControllerStyleActionSheet];
            [actionSheet addAction:[UIAlertAction actionWithTitle:@"QQ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                NSLog(@"QQ被点击");
            }]];
            [actionSheet addAction:[UIAlertAction actionWithTitle:@"人人" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                NSLog(@"人人被点击");
            }]];
            [actionSheet addAction:[UIAlertAction actionWithTitle:@"sina" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                NSLog(@"sina被点击");
            }]];
            //取消
            [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                NSLog(@"取消");
            }]];
            //删除
            [actionSheet addAction:[UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                NSLog(@"删除被点击");
            }]];
            //模态跳转
            [self presentViewController:actionSheet animated:YES completion:nil];
            
        }
            break;
        case 103:
        {
            //alert 自带 textField
            UIAlertController *alertText = [UIAlertController alertControllerWithTitle:@"登录" message:@"登录账号" preferredStyle:UIAlertControllerStyleAlert];
            //增加textField
            [alertText addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                //这个block 初始化 alert的时候回调 可以对textField进行设置
                textField.placeholder = @"请输入用户名";
            }];
            [alertText addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                //这个block 初始化 alert的时候回调 可以对textField进行设置
                textField.placeholder = @"请输入密码";
                textField.secureTextEntry = YES;
            }];
            //增加按钮
            [alertText addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                NSLog(@"取消被点击");
            }]];
            [alertText addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                //打印 textField的内容
                //alertText.textFields获取 textfield数组
                NSLog(@"name:%@",[alertText.textFields[0] text]);
                NSLog(@"passwd:%@",[alertText.textFields[1] text]);
            }]];
            
            [self presentViewController:alertText animated:YES completion:nil];
        }
            break;

转载于:https://www.cnblogs.com/cdp-snail/p/4918595.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值