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中的代码

}];

iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建的更多相关文章

  1. dataset数据来源方式两种,页面展示

    这两种方式都能获取到报表类别数据. <%--ds 数据源来自JavaBean--%><model:dataset id="ds"> <model:re ...

  2. 正则表达式split匹配多种例如 “】”,“,”两种(页面级中英文切换方案)

    在做登陆界面的时候,因为涉及到中英文 因为前后台已经分离,所以前端需要自行设计中英文 做法: 编写两个文件,一个中文文件,一个是英文文件,分别放在对应的目录下面 文件的内容 { "login ...

  3. Selector、shape详解,注意这两种图像资源都以XML方式存放在drawable不带分辨率的文件夹中

    Selector.shape详解(一) Selector的结构描述: <?xml version="1.0" encoding="utf-8"?> ...

  4. UIAlertView、UIActionSheet兼容iOS8

    链接地址:http://blog.csdn.net/nextstudio/article/details/39959895?utm_source=tuicool 1.前言 iOS8新增了UIAlert ...

  5. struts2+spring的两种整合方式

    也许有些人会因为学习了struts1,会以为struts2.struts1与spring的整合也是一样的,其实这两者相差甚远.下面就来讲解一下struts2与spring的整合两种方案.(部分转载,里 ...

  6. thinkphp的钩子的两种配置和两种调用方法

    thinkphp的钩子行为类是一个比较难以理解的问题,网上有很多写thinkphp钩子类的文章,我也是根据网上的文章来设置thinkphp的钩子行为的,但根据这些网上的文章,我在设置的过程中,尝试了十 ...

  7. Unity中有两种Animation Clip

    http://blog.csdn.net/zzxiang1985/article/details/51291861 在Unity中,我们有两种方法创建Animation Clip. 一种(后面简称方法 ...

  8. 关于js中两种定时器的设置及清除

    1.JS中的定时器有两种: window.setTimeout([function],[interval]) 设置一个定时器,并且设定了一个等待的时间[interval],当到达时间后,执行对应的方法 ...

  9. android textView 添加超链接(两种实现方式)

    在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现 在textView添加超链接,有两种方式 ...

随机推荐

  1. python __new__()分析

    我们来看下下面类中对__new__()方法的实现: class Demo(object): def __init__(self): print '__init__() called...' def _ ...

  2. Algorithm——最长公共前缀

    一.问题 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow ...

  3. 动态设置热区coords的坐标

    window.onresize = adjuest; function adjuest(){ var picw = $(".imgbox img").width(); var pi ...

  4. mysql索引是什么?索引结构和使用详解

    索引是什么 mysql索引: 是一种帮助mysql高效的获取数据的数据结构,这些数据结构以某种方式引用数据,这种结构就是索引.可简单理解为排好序的快速查找数据结构.如果要查“mysql”这个单词,我们 ...

  5. 解决 spring cloud 项目的 com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect 错误信息

    在项目中引入:引入hystrix依赖,如下 <dependency> <groupId>org.springframework.cloud</groupId> &l ...

  6. Python爬虫教程-16-破解js加密实例(有道在线翻译)

    python爬虫教程-16-破解js加密实例(有道在线翻译) 在爬虫爬取网站的时候,经常遇到一些反爬虫技术,比如: 加cookie,身份验证UserAgent 图形验证,还有很难破解的滑动验证 js签 ...

  7. winform 写入和读取TXT文件

    C# winform写入和读取TXT文件 string str; str=this.textBox1.Text; StreamWriter sw = new StreamWriter(Applicat ...

  8. Java SpringMVC学习--基础配置

    快速开始一个基于SpringMVC框架的web项目 开发工具 Eclipse neon.2 运行环境 tomcat8.5 1.在Eclipse中新建一个web项目:File-New-Dynamic W ...

  9. laravel-5-doctrine-2 教程

    Open up a Terminal again, cd into learning folder and run: composer require "laravel-doctrine/o ...

  10. dbms_stats应用相关

    Q:     DBMS_STATS.GATHER_SCHEMA_STATS ('schema_name');        使用这个收集统计信息,estimate_percent使用默认值       ...