IOS8 UIAlertController 弹框
本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/35551769
IOS8中,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];
- <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>
- 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和实现响应的回调等。
IOS8 UIAlertController 弹框的更多相关文章
- UIAlertController:弹框4步走
对于大多数的App来说,弹框这种交互方式基本上是必不可少的.在新的iOS系统中(具体版本我忘了),以前的UIAlertView被弃用,而换成了现在的UIAlertController. UIAlite ...
- iOS8 UIAlertController弹出框中添加视图(例如日期选择器等等)
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerMode ...
- IOS 弹框AlterView的使用(IOS8.0以前使用)UIAlertController(IOS9.0使用)
#pragma mark - 代理方法 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath ...
- ios-消息弹框之UIAlertView, UIActionSheet以及UIAlertController小结
首先storyboard中创建对应按钮并拖线,来演示不同的效果 首先点击了actionSheet按钮效果如图 实现弹框需要遵守设置代理,遵守协议. 效果就是从底部向上弹起来的框框. 通过对按钮的点击输 ...
- 参考bootstrap中的popover.js的css画消息弹框
前段时间小颖的大学同学给小颖发了一张截图,图片类似下面这张图: 小颖当时大概的给她说了下,其实小颖也不知道上面那个三角形怎么画嘻嘻,给她说了DOM结构,具体的css让她自己百度,今天小颖自己参考boo ...
- 安卓客户端a标签长按弹框提示解决办法
昨天工作时候发现一个bug,是关于a标签的,在安卓客户端中,如果是a标签的话,长按会出现一个弹框,如图所示 是因为安卓客户端的长按触发机制,以后进行wap端开发的时候,如果用到跳转页面尽量不要用a标签 ...
- Jquary入门(添加 修改 表单元素)+ JSON+弹框
字符串拼接 计算机语言 都是 对 数据的处理(获取/修改数据) 添加元素 除了 固定的方法添加 以外 都是 字符串拼接(拼接成固定格式即可执行). 1.表单添加元素 append() 方 ...
- ios UIWebView自定义Alert风格的弹框
之前开发过一个App,因为公司之前写好了网页版的内容和安卓版本的App,我进去后老板要求我ios直接用网页的内容,而不需要自己再搭建框架.我一听,偷笑了,这不就是一个UIWebView吗?简单! 但是 ...
- weui 弹框中的单选效果
<!--性别修改弹框--> <div class="weui_dialog_alert" id="doctorSexDialog" style ...
随机推荐
- Wmap5 测试80端口 Your port 80 is actually used by :Server: Microsoft-HTTPAPI/2.0
问题:win7系统! 在wamp5的apache启动不了: 目录下点击[测试80端口]的时候提示:Your port 80 is actually used by : Server: Microsof ...
- poj 1981 Circle and Points
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 8131 Accepted: 2899 ...
- 【BZOJ2693】jzptab (莫比乌斯反演)
Description 给你$n$,$m$,求 $\sum^n_{i=1} \sum^m_{j=1} \ lcm(x,y)$ 答案对$100000009$取模. 多组数据. Input 第一行有一个正 ...
- [LeetCode] Sort Colors 只有3个类型的排序
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- 在4418平台上如何配置GPIO口的状态
硬件 ------------------------------------------------------------------------------------------------- ...
- unity3d自动寻路教程
U3D的自动寻路插件是不少,但是其实U3D的PRO版本就提供了相当实用的自动寻路组件了,以下教程分别讲解自动寻路的路径选择优先,上楼梯跳下的条件判断等等实用方法,教程分三编,但这个教程没有讲到Navm ...
- codeforces gym 100825 D Rings
这题果然就是个暴力题.... 看每个T的四个方向,有'.',或者在边界上就填1 不然就填四个方向上最小的那个数再加1 然而写wa了几发,有点蠢... #include <bits/stdc++. ...
- 洛谷——P1126 机器人搬重物
P1126 机器人搬重物 题目描述 机器人移动学会(RMI)现在正尝试用机器人搬运物品.机器人的形状是一个直径1.6米的球.在试验阶段,机器人被用于在一个储藏室中搬运货物.储藏室是一个N*M的网格,有 ...
- OAuth 2.0 in Web API #Reprinted
http://www.codebetter.com/howarddierking/2011/10/11/oauth-2-0-in-web-api/
- 【springcloud】使用@FEIGNCLIENT时,报JAVA.LANG.NOCLASSDEFFOUNDERROR: FEIGN/FEIGN$BUILDER错
引用地址:http://www.cnblogs.com/ellacan/p/8822374.html 错误信息: Caused by: java.lang.ClassNotFoundException ...