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. BZOJ2882: 工艺(后缀数组)

    题意 题目链接 Sol 直接把序列复制一遍 后缀数组即可 在前\(N\)个位置中取\(rak\)最小的输出 #include<bits/stdc++.h> using namespace ...

  2. 规范的web前端代码

    web前端的代码规范主要针对的是HTML,CSS和javaScript代码. 前端代码规范在不同场合会有差异,但是规范的前端代码应该具有以下特征: 1.符合标准 所谓的标准是指W3C指定的web标准, ...

  3. eayui grid 每一页的行号都是从1开始

    问题背景: easyui 需要显示行号的时候,我们只需要设置  rownumbers: true, 但是 不管是在哪一页,行号都是从1开始,不能连续 我们在分页的 onSelectPage 函数里去执 ...

  4. 回溯法最优装载问题(java)

    1.问题描述:      有一批共有 n 个集装箱要装上两艘载重量分别为 c1 和 c2 的轮船,其中集装箱 i 的重量为 w[i], 且重量之和小于(c1 + c2).装载问题要求确定是否存在一个合 ...

  5. 树莓派搭建web服务器(详细且良心)

    安装Apache Apache服务器可以从Debian的源中下载.可以用apt下载. 首先要更新apt的软件列表.如果不运行sudo apt-get updata的话,apt软件就不知道有没有新的软件 ...

  6. eclipse安装checkStyle

    今天用eclipse mars 安装checkstyle 代码测试工具,安装完后重启竟然没有,最后发现原来是 自己安装的步骤错了,记录下. 1. 我的版本是:Version: Mars.2 Relea ...

  7. Suse LAMP setup

    This page will describe the steps you have to take to install LAMP, which stands for Linux Apache Ma ...

  8. laravel5.5 自定义验证规则——手机验证RULE

    相信很多小伙伴和我一样烦恼,laravel没有自带手机号的验证,每次验证手机号都要写正则这类的规则,每次都是repeat yourself!违背了编码的一个原则,就是Don't repeat your ...

  9. php集群和分布式理解

    首先架构层次来说: php的集群是指很多台服务器处理同样的工作,指的是硬件上的一般,比如slb负载均衡主要作用是有多台服务器处理同样的工作, php分布式是指多台服务器处理不同的工作,指的是业务上的一 ...

  10. yii2.0的gradview点击按钮通过get方式传参

    1.直接看views层里的代码就可以了 , <!--?= GridView::widget([ 'dataProvider' =--> $dataProvider, 'filterMode ...