zoukankan      html  css  js  c++  java
  • iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建

    1.

    Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert.  

    //UIAlertView和UIAlertViewDelegate(代理被给用block回调,更简单)在iOS8及以后版本中被弃用,改用风格为UIAlertControllerStyleAlertUIAlertController来替代。

    2.

    In apps that run in versions of iOS prior to iOS 8, use the UIAlertView class to display an alert message to the user. An alert view functions similar to but differs in appearance from an action sheet (an instance of UIActionSheet).

    //iOS8以前版本中UIAlertView和UIActionSheet有着类似的功能,却通过不同的类来生成。言外之意,iOS8以后版本,UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来生成。

    3.

    (1) iOS 8以前版本  如何创建UIAlertView ?

    - (instancetype)initWithTitle:(NSString *)title
                          message:(NSString *)message
                         delegate:(id)delegate
                cancelButtonTitle:(NSString *)cancelButtonTitle
                otherButtonTitles:(NSString *)otherButtonTitles,
    ...

    (2) iOS 8及以后版本  如何创建UIAlertView ?

    1. UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
    2. message:@"This is an alert.” preferredStyle:UIAlertControllerStyleAlert];
    3. UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK”style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
    4. [alert addAction:defaultAction];
    5. [self presentViewController:alert animated:YES completion:nil];

    4.

      (1)iOS 8以前版本  如何创建UIActionSheet ?

    - (instancetype)initWithTitle:(NSString *)title

                         delegate:(id<UIActionSheetDelegate>)delegate

                cancelButtonTitle:(NSString *)cancelButtonTitle

           destructiveButtonTitle:(NSString *)destructiveButtonTitle

                otherButtonTitles:(NSString *)otherButtonTitles

    ...

    (2)iOS 8及以后版本  如何创建UIActionSheet ?

        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"苍老师你好" message:@"听说你的新片被下载了9999次" preferredStyle:UIAlertControllerStyleAlert];

        

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

            self.lblTarget.text = [NSString stringWithFormat:@"点击AlertView确定按钮后,产生随机数"];

            self.lblTarget.textColor = [UIColor redColor];

        }]; //点击按钮后通过block回调执行此方法,故没必要再使用代理了

        

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

        }]; /*UIAlertActionStyleCancel 蓝色字体,加粗;

             UIAlertActionStyleDefault 字体蓝色,不加粗;

             UIAlertActionStyleDestructive字体红色,不加粗;

             */

        [alertVC addAction:action1];

        [alertVC addAction:action2];

         [self presentViewController:alertVC animated:YES completion:nil];

    5. 

    (1)iOS 8以前,如何利用代理监听UIAlertView的点击事件 ?

     

    (2)iOS 8以后,如何利用block回调来实现UIAlertView的点击事件 ?

    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定” style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

    //点击“确定”按钮后,执行该block中的代码

     

    }];

    iOS开发者交流群:180080550
  • 相关阅读:
    SourceTree用法
    @Valid注解的使用
    mysql命令导入导出sql文件
    eclipse集成svn及使用
    eclipse设置
    @Component
    购物车单选全选,计算总价,出现个小问题,没找到.....
    十三、迭代器,分部类,文件流,内存流,缓存,枚举(IEnumerator接口),线程(单线程,多线程)
    十二、事件,委托,泛型委托,集合(泛型和非泛型),Lambda表达式(声明委托,使用委托,简单的委托示例,action<T>和func<t>委托,多播委托,匿名方法,Lambda表达式,参数,事件)
    十一、接口(接口的概念,实现,继承,实现)、抽象类与抽象方法(抽象类,抽象方法概念,使用)
  • 原文地址:https://www.cnblogs.com/stevenwuzheng/p/4890499.html
Copyright © 2011-2022 走看看