zoukankan      html  css  js  c++  java
  • iOS8中UIAlertController的使用

    iOS8中的UIAlertController包括了之前的UIAlertView和UIActionSheet,将它们集合成了自己的style;

    1------------UIAlertControllerStyleAlert-----原有的UIAlertView 

     1   UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"alertC" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
     2     
     3     //preferredStyle--只读
     4     //打印选择的AlertController的类型 actionSheet--0 alertView--1
     5     NSLog(@"%ld",alertC.preferredStyle);
     6     //获取alertC的标题和信息
     7     NSLog(@"%@",alertC.title);
     8     NSLog(@"%@",alertC.message);
     9     //更改标题
    10     alertC.title = @"title change";
    11     
    12     //直接给alertC添加事件执行按钮actionTitle(只能添加一个)
    13     /*
    14      [alertC addAction:[UIAlertAction actionWithTitle:@"actionTitle" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    15      //点击actionTitle时的回调方法
    16      }]];
    17      */
    18     
    19     //添加多个按钮
    20     //没有任何代理的情况下,在我们点击alertView界面中的按钮时,就不需要用buttonIndex来区分我们点击的是哪个按钮,同时一个界面上多个alertView时,也不需要用tag值来区分你到底点击的是哪一个alertView上的按钮了
    21     //这样便于我们的逻辑思维,但是代码量并没有减少
    22     UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancle"@"Cancle action")
    23                                                      style:UIAlertActionStyleCancel
    24                                                    handler:^(UIAlertAction *action) {
    25                                                        //cancle对应执行的代码
    26                                                        NSLog(@"cancle action");
    27                                                    }];
    28     UIAlertAction *action1 = [UIAlertAction actionWithTitle:NSLocalizedString(@"sure"@"Sure action")
    29                                                       style:UIAlertActionStyleDefault
    30                                                     handler:^(UIAlertAction *action) {
    31                                                         //sure对应执行的代码
    32                                                         NSLog(@"sure action");
    33                                                     }];
    34     
    35     [alertC addAction:action];
    36     [alertC addAction:action1];
    37     
    38     //alertView的输入框 sheet类型中没有 但是sheet类型的UIAlertController可以添加textField 当用户要显示sheet时程序会崩
    39     [alertC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    40         textField.placeholder = @"textFiled";
    41     }];
    42     
    43     //在这里不管是alertView还是actionSheet都是一个独立的Cotroller,所以这里需要通过presentViewController来展现我们的alertView或者actionSheet
    44     [self presentViewController:alertC animated:YES completion:nil];

      

    2---------------UIAlertControllerStyleActionSheet----原有的UIActionSheet

     1 UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"alertC" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];
     2     
     3     UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancle"@"Cancle action")
     4                                                      style:UIAlertActionStyleCancel
     5                                                    handler:^(UIAlertAction *action) {
     6                                                        NSLog(@"cancle action");
     7                                                    }];
     8     UIAlertAction *action1 = [UIAlertAction actionWithTitle:NSLocalizedString(@"sure"@"Sure action")
     9                                                       style:UIAlertActionStyleDefault
    10                                                     handler:^(UIAlertAction *action) {
    11                                                         NSLog(@"sure action");
    12                                                     }];
    13     
    14     [alertC addAction:action];
    15     [alertC addAction:action1];
    16     [self presentViewController:alertC animated:YES completion:nil];
  • 相关阅读:
    ftp连接
    Excel表格内容导出到页面
    jquery 元素前或插入一元素
    sql 查出相同的记录 并把相同记录 显示在一起
    ie 使用window.open页面报错
    java生成word文档
    myeclipse导入项目
    java生成临时文件夹和删除临时文件夹
    正则学习笔记
    React和Vue的组件更新比较
  • 原文地址:https://www.cnblogs.com/NINIiOS/p/3992247.html
Copyright © 2011-2022 走看看