UIAlertController的使用,代替UIAlertView和UIActionSheet
在iOS8以后,UIAlertView就开始被抛弃了。
取而代之是UIAlertController
以前是警示框这样写:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入用户名、密码和服务器" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
效果如图:

现在是这样写:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入用户名、密码和服务器" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消按钮");
}];
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确定按钮");
}]; [alertController addAction:cancelAction];
[alertController addAction:OKAction]; [self presentViewController:alertController animated:YES completion:nil];
效果如图:

添加多个Action会自动向下排列
上面代码中再添加一个
UIAlertAction *DesAction = [UIAlertAction actionWithTitle:@"Destory" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了Destory按钮");
}];
[alertController addAction:DesAction];

如果提示菜单中有“取消”按钮的话,那么它永远都会出现在菜单的底部
//冻结确定按钮
OKAction.enabled = NO;
添加文本框
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"Email";
textField.keyboardType = UIKeyboardTypeEmailAddress;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"Password";
textField.secureTextEntry = YES;
}];

UIActionSheet也用这个取代了。。方法是在初始化的时候把类型改一下就OK。但是UIActionSheet是不能加文本框的!!
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入用户名、密码和服务器" preferredStyle:UIAlertControllerStyleActionSheet];

P.S 用通知监听用户名和密码输入, 这里有篇介绍得很好的文章:
http://blog.csdn.net/lengshengren/article/details/39896037
UIAlertController的使用,代替UIAlertView和UIActionSheet的更多相关文章
- iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建
1. Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated. ...
- UIAlertView、UIActionSheet兼容iOS8
链接地址:http://blog.csdn.net/nextstudio/article/details/39959895?utm_source=tuicool 1.前言 iOS8新增了UIAlert ...
- UIAlertView及UIActionSheet 在ios8极其以下版本的兼容问题解决方案
本文转载至 http://www.aichengxu.com/view/35326 UIAlertView及UIActionSheet在ios8中被放弃,其功能将完全由UIAlertControlle ...
- iOS 8 中 UIAlertView 和 UIActionSheet 河里去了?
iOS 8 中 UIAlertView 和 UIActionSheet 河里去了? 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...
- UIAlertView、 UIActionSheet
一.UIAlertView. UIActionSheet都是ios系统自带的弹出式对话框,当UIAlertView或UIActionSheet弹出来时用户无法与应用界面中的其它控件交互,UIAlert ...
- iOS开发——UI篇Swift篇&UIAlertView/UIActionSheet
UIAlertView/UIActionSheet UIAlertView //一个按钮的提醒 @IBAction func oneButtonAler() { //创建单一按钮提醒视图 let on ...
- 用block将UIAlertView与UIActionSheet统一起来
用block将UIAlertView与UIActionSheet统一起来 效果 1. 将代理方法的实例对象方法转换成了类方法使用 2. 要注意单例block不要长期持有,用完就释放掉 源码 https ...
- iOS:简单使用UIAlertVIew和UIActionSheet
做iOS开发的同学想必都用过UIAlertVIew或者UIActionSheet.UIAlertVIew 可以弹出一个出现在屏幕中间的提示视图,给用户展示信息,并让用户自己选择操作,UIActionS ...
- iOS - 提示信息 - UIAlertView、UIActionSheet、UIAlertController的实际应用
1.UIAlertView(屏幕中央弹出框)(不需要服从代理) UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@" ...
随机推荐
- Dom对象的经常用法
Dom对象的经常用法: (1)getElementById() 查询给定ID属性值的元素,返回该元素的元素节点 1. 查询给定ID属性值的元素,返回该元素的元素节点.也称为元素对象. ...
- Phalcon 开发工具(Phalcon Developer Tools)
Phalcon提供的这个开发工具主要是用来辅助开发,比方生成一些程序的基本框架.生成控制器模型等. 使用这个工具我们仅仅须要一个简单的命令就可以生成应用的基本框架. 很重要: 要使用这个工具我们必需要 ...
- coco2d-js demo程序之滚动的小球
近期有一个游戏叫围住神经猫,报道说是使用html5技术来做的. html5的跨平台的优良特性非常不错.对于人手不足,技术不足,选用html5技术实现跨平台的梦想真是不错. 近期在看coco2d-js这 ...
- LeetCode 283 Move Zeroes(移动全部的零元素)
翻译 给定一个数字数组.写一个方法将全部的"0"移动到数组尾部.同一时候保持其余非零元素的相对位置不变. 比如,给定nums = [0, 1, 0, 3, 12],在调用你的函数之 ...
- 【Mongodb教程 第十三课 】PHP mongodb 的增删改查使用
<pre> <?php #phpinfo();die; #其他链接方式 #$conn=new Mongo(); #连接本地主机,默认端口. #$conn=new Mongo(&quo ...
- CASE函数 sql server——分组查询(方法和思想) ref和out 一般处理程序结合反射技术统一执行客户端请求 遍历查询结果集,update数据 HBuilder设置APP状态栏
CASE函数 作用: 可以将查询结果集的某一列的字段值进行替换 它可以生成一个新列 相当于switch...case和 if..else 使用语法: case 表达式/字段 when 值 then ...
- js的几种循环语句
//js种的循环语句 //while与do while的区别是while是满足条件后才执行 //do while是不管满不满足条件都会执行一次 //for 循环与while,do while相比循环结 ...
- 嵌入式开发之davinci---IPIPE、IPIPEIF and ISIF这三者有什么区别
(1)缩写概念 (2)各自区别 (3)不同sensor 采集接口 (4)采集后的数据链路link (5)8127 中的iss和ipipe的区别 (1)缩写概念 http://www.ti.com.cn ...
- Oracle - 数据更新 - 事务
/* 事务 事务是为了控制数据异步访问所使用的一种技术 就类似于java中的锁机制 synchronized,只不过功能更加强大 事务不能进行嵌套,当我们开启一个事务的之后作的每一次dml语句都属于这 ...
- execute ps1 with pwsh.exe
pwsh -file C:\Users\clu\source\repos\Edenred\LISA_5.0.0.0\LISA.ControlPanel\LISA.ControlPanel\bin\Re ...