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. node.js学习网址

    七天学会NodeJS: http://www.open-open.com/lib/view/1392611872538 https://nodejs.org/api/ Node.js v0.10.18 ...

  2. 第一行代码 10.2使用HTTP协议访问网络 HttpURLConnection代码中的问题

    实现HttpURLConnection代码的时候,遇到了问题. 怎样点击途中Send Request按钮,没有任何改变. 最后将MainActivity中的一段代码URL url = new URL( ...

  3. 微信小程序,动态改变样式

    小程序目前没有修改样式api,但是可以利用数据绑定实现动态改变样式,可以用view标签模拟page然后改变view标签的样式,以下案例演示了如果改变page背景颜色: <view class=& ...

  4. Angularjs ngTable使用备忘

    项目中用到angularjs的表格ng-table,功能相当强大,像搜索.排序.checkbox.分页.每页表格显示数目等都有.API,demo什么的也只能参考官网了.这里做个备忘,哪天肯定还会用到. ...

  5. JAVA的静态方法,静态变量,静态类。

    静态变量和静态方法都属于静态对象,它与非静态对象的差别需要做个说明. (1)Java静态对象和非静态对象有什么区别? 比对如下: 静态对象                                ...

  6. idea 出现 java.lang.OutOfMemoryError: PermGen space

    今天在项目启动时候,刚刚启动 就 报了 Exception in thread "http-bio-8080-exec-1" 之后 出现了 java.lang.OutOfMemor ...

  7. GridControl 应用 z

    DevExpress学习系列(控件篇):GridControl的基本应用 一般属性设置 不显示分组框:Gridview->Option View->Show Group Panel=fal ...

  8. Python 编码为什么那么蛋疼?

    据说,每个做 Python 开发的都被字符编码的问题搞晕过,最常见的错误就是 UnicodeEncodeError.UnicodeDecodeError,你好像知道怎么解决,遗憾的是,错误又出现在其它 ...

  9. Web博文目录

    前言 博客写的多了,自己翻起来也费劲,这里就进行一下整合. 以前设想自己做DBA,做运维,没想到最后还要走开发这条路,干一行就爱一行...学的扎实点,工作起来也会轻松.—— 送给奋斗的自己 1 Jav ...

  10. 【Z】段错误Segment Fault定位,即core dump文件与gdb定位

    使用C++开发系统有时会出现段错误,即Segment Fault.此类错误程序直接崩溃,通常没有任何有用信息输出,很难定位bug,因而无从解决问题.今天我们介绍core dump文件,并使用gdb进行 ...