zoukankan      html  css  js  c++  java
  • UIAlertController

    IOS8 UIAlertController 

     

    IOS8中,UIActiconSheet已被废弃,同时基于UIActionSheet自定义的也将无效果。

    Apple将UIActionSheet和UIAlertView整合成一个接口UIAlertController。

    原来的是一个view,展示在window视图之上。现在改成了controller,展示方式变成由当前的controller直接present出来。

    下面看看具体的接口:

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"This is Title"
    message:@"This is message"
    preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"Action 1 (Default Style)"
    style:UIAlertActionStyleDefault
    handler:^(UIAlertAction *action) {
    NSLog(@"Action 1 Handler Called");
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"Action 2 (Cancel Style)"
    style:UIAlertActionStyleCancel
    handler:^(UIAlertAction *action) {
    NSLog(@"Action 2 Handler Called");
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"Action 3 (Destructive Style)"
    style:UIAlertActionStyleDestructive
    handler:^(UIAlertAction *action) {
    NSLog(@"Action 3 Handler Called");
    }]];

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

    生成UIAlertController的时候可以指定title、message,通过preferredStyle可以指定具体是Alert还是ActionSheet。

    typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
    UIAlertControllerStyleActionSheet = 0,
    UIAlertControllerStyleAlert
    } NS_ENUM_AVAILABLE_IOS(8_0);

    通过addAction接口添加具体按钮,设置按钮title、style和使用block方式直接加入按钮响应接口。

    style有以下几种:

    typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
    UIAlertActionStyleDefault = 0,
    UIAlertActionStyleCancel,
    UIAlertActionStyleDestructive
    } NS_ENUM_AVAILABLE_IOS(8_0);

    与原来的UIActionSheet和UIAlertView比较:
    1、视觉上没有改变,跟之前的样式保持一致;
    2、改为controller方式后,控件的生命周期能够更好的控制;方便的弹出和收起
    3、当前controller弹出UIAlertController后,再次present controller必须在UIAlertController的基础上present。present后,UIAlertController会被盖住。而之前的UIActionSheet和UIAlertView由于是add在window上面的,当在弹出他们的controller基础上再present controller的话,UIActionSheet和UIAlertView弹框仍然保留在最上方。
    4、修改为controller方式后,接口更加简单,而且按钮响应方式更加明了简介,不需要在设置delegate和实现响应的回调等。

  • 相关阅读:
    激活函数
    第五章 Odoo 12开发之导入、导出以及模块数据
    第四章 Odoo 12 开发之模块继承
    第三章 Odoo 12 开发之创建第一个 Odoo 应用
    第二章 Odoo 12开发之开发环境准备
    第一章 使用开发者模式快速入门 Odoo 12
    【linux之路】常用的命令
    【python之路46】内置函数2,是【python之路18】的补充
    【python之路45】tornado的用法 (三)
    【python之路44】tornado的用法 (二)
  • 原文地址:https://www.cnblogs.com/sunhaijin/p/4366588.html
Copyright © 2011-2022 走看看