本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/35551769

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

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

下面看看具体的接口:

  1. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"This is Title"
  2. message:@"This is message"
  3. preferredStyle:UIAlertControllerStyleAlert];
  4. [alert addAction:[UIAlertAction actionWithTitle:@"Action 1 (Default Style)"
  5. style:UIAlertActionStyleDefault
  6. handler:^(UIAlertAction *action) {
  7. NSLog(@"Action 1 Handler Called");
  8. }]];
  9. [alert addAction:[UIAlertAction actionWithTitle:@"Action 2 (Cancel Style)"
  10. style:UIAlertActionStyleCancel
  11. handler:^(UIAlertAction *action) {
  12. NSLog(@"Action 2 Handler Called");
  13. }]];
  14. [alert addAction:[UIAlertAction actionWithTitle:@"Action 3 (Destructive Style)"
  15. style:UIAlertActionStyleDestructive
  16. handler:^(UIAlertAction *action) {
  17. NSLog(@"Action 3 Handler Called");
  18. }]];
  19. [self presentViewController:alert animated:YES completion:nil];
  1. <span style="font-family:Arial, Helvetica, sans-serif;">生成UIAlertController的时候可以指定title、message,通过preferredStyle可以指定具体是Alert还是</span><span style="color: rgb(61, 29, 129); font-family: Menlo; font-size: 14px;">ActionSheet</span>
  1. typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
  2. UIAlertControllerStyleActionSheet = 0,
  3. UIAlertControllerStyleAlert
  4. } NS_ENUM_AVAILABLE_IOS(8_0);

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

style有以下几种:

  1. typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
  2. UIAlertActionStyleDefault = 0,
  3. UIAlertActionStyleCancel,
  4. UIAlertActionStyleDestructive
  5. } 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和实现响应的回调等。

IOS8 UIAlertController 弹框的更多相关文章

  1. UIAlertController:弹框4步走

    对于大多数的App来说,弹框这种交互方式基本上是必不可少的.在新的iOS系统中(具体版本我忘了),以前的UIAlertView被弃用,而换成了现在的UIAlertController. UIAlite ...

  2. iOS8 UIAlertController弹出框中添加视图(例如日期选择器等等)

    UIDatePicker *datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerMode ...

  3. IOS 弹框AlterView的使用(IOS8.0以前使用)UIAlertController(IOS9.0使用)

    #pragma mark - 代理方法 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath ...

  4. ios-消息弹框之UIAlertView, UIActionSheet以及UIAlertController小结

    首先storyboard中创建对应按钮并拖线,来演示不同的效果 首先点击了actionSheet按钮效果如图 实现弹框需要遵守设置代理,遵守协议. 效果就是从底部向上弹起来的框框. 通过对按钮的点击输 ...

  5. 参考bootstrap中的popover.js的css画消息弹框

    前段时间小颖的大学同学给小颖发了一张截图,图片类似下面这张图: 小颖当时大概的给她说了下,其实小颖也不知道上面那个三角形怎么画嘻嘻,给她说了DOM结构,具体的css让她自己百度,今天小颖自己参考boo ...

  6. 安卓客户端a标签长按弹框提示解决办法

    昨天工作时候发现一个bug,是关于a标签的,在安卓客户端中,如果是a标签的话,长按会出现一个弹框,如图所示 是因为安卓客户端的长按触发机制,以后进行wap端开发的时候,如果用到跳转页面尽量不要用a标签 ...

  7. Jquary入门(添加 修改 表单元素)+ JSON+弹框

    字符串拼接 计算机语言 都是 对  数据的处理(获取/修改数据)  添加元素  除了  固定的方法添加 以外 都是   字符串拼接(拼接成固定格式即可执行). 1.表单添加元素  append() 方 ...

  8. ios UIWebView自定义Alert风格的弹框

    之前开发过一个App,因为公司之前写好了网页版的内容和安卓版本的App,我进去后老板要求我ios直接用网页的内容,而不需要自己再搭建框架.我一听,偷笑了,这不就是一个UIWebView吗?简单! 但是 ...

  9. weui 弹框中的单选效果

    <!--性别修改弹框--> <div class="weui_dialog_alert" id="doctorSexDialog" style ...

随机推荐

  1. 【CF559C】 Gerald and Giant Chess(计数,方案数DP,数论)

    题意:给出一个棋盘为h*w,现在要从(1,1)到(h,w),其中有n个黑点不能走,问有多少种可能从左上到右下 (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000),答案模10^9+7 思路:从 ...

  2. net6:创建Membership对象数据源的代码

    原文发布时间为:2008-07-30 -- 来源于本人的百度文章 [由搬家工具导入] 添加了一个db的类作为了对象数据源: using System;using System.Data;using S ...

  3. Enable and Use Remote Commands in Windows PowerShell

    The Windows PowerShell remoting features are supported by the WS-Management protocol and the Windows ...

  4. Android 动态隐藏显示导航栏,状态栏

    Talk is cheap, show me the code. --Linus Torvalds Okay, here: 一.导航栏: [java] view plain copy private  ...

  5. 遍历删除List中的元素,会报错?

    经常会碰到遍历集合,然后删除里面的对象报错, 纠结半天, 百度了一下,有大神说不能用for-each,  for , 只能用迭代器,真的吗?  我就删成功了呢,看代码,请大神们指正! public s ...

  6. AC日记——软件包管理器 洛谷 P2416

    题目描述 Linux用户和OSX用户一定对软件包管理器不会陌生.通过软件包管理器,你可以通过一行命令安装某一个软件包,然后软件包管理器会帮助你从软件源下载软件包,同时自动解决所有的依赖(即下载安装这个 ...

  7. 牛客网 牛客练习赛11 D.求距离

    D.求距离 链接:https://www.nowcoder.com/acm/contest/59/D来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言6 ...

  8. Codeforces Educational Round 33 题解

    题目链接   Codeforces Educational Round 33 Problem A 按照题目模拟,中间发现不对就直接输出NO. #include <bits/stdc++.h> ...

  9. .Net Core中的配置文件源码解析

    一.配置简述 之前在.Net Framework平台开发时,一般配置文件都是xml格式的Web.config,而需要配置其他格式的文件就需要自己去读取内容,加载配置了..而Net Core支持从命令行 ...

  10. 第三章 poj 1064——关于带精度的二分法

    /* 题意:给定n个实数l[i],给定一个k 问:求最大的ans,使得sum l[i]/ans i=1 to n >=k,且ans最大*/ #include <iostream> # ...