UIAlertView在IOS 8以上版本已经过时了,官方推荐我们使用UIAlertController代替UIAlertView、UIActionSheet

1、UIAlertController显示普通的Alert

- (IBAction)showAlert:(UIButton *)sender {
//显示提示框
//过时
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
// [alert show];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title"
message:@"This is an alert."
preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}]; [alert addAction:defaultAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}

2、UIAlertController显示带文本输入的的Alert

3、UIAlertController显示ActionSheet

- (IBAction)showSheet:(UIButton *)sender {
//显示弹出框列表选择
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title"
message:@"This is an Sheet."
preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}];
UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}];
UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
NSLog(@"action = %@", action);
}];
[alert addAction:saveAction];
[alert addAction:cancelAction];
[alert addAction:deleteAction];
[self presentViewController:alert animated:YES completion:nil];
}

iOS - UIAlertController三种显示提示框代码的更多相关文章

  1. iOS的三种多线程技术NSThread/NSOperation/GCD

    1.iOS的三种多线程技术 1.NSThread 每个NSThread对象对应一个线程,量级较轻(真正的多线程) 2.以下两点是苹果专门开发的"并发"技术,使得程序员可以不再去关心 ...

  2. 关于jsp和html页面中的三种弹出框

    代码: <!-- 引入jquery 由于在下面使用jquery选择器,与弹出框无关 --> <script type="text/javascript" src= ...

  3. echarts —— tooltip 鼠标悬浮显示提示框属性

    最近一直在使用echarts,当然也被其中的各种属性整的头大,记录一下其中遇到的问题. tooltip:鼠标悬浮时显示的提示框. 今天想要记录的是[自定义提示框的内容],如下图,鼠标悬浮时提示框内显示 ...

  4. ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)

    介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...

  5. JavaScript中的三种弹出框的区别与使用

    JavaScript中有三种原生的弹出框,分别是alert.confirm.prompt.分别表示弹出框.确认框.信息框. 以下是示例代码: <!DOCTYPE html> <htm ...

  6. js基础 三种弹出框 数据类型

    总结:js三个组成部分ES:语法DOM:对象模型 => 通过js代码与页面文档(出现在body中的所有可视化标签)进行交互BOM:对象模型 => 通过js代码与浏览器自带功能进行交互 引入 ...

  7. js值类型转换(boolean/String/number),js运算符,if条件,循环结构,函数,三种弹出框

    js值类型转换 number | string | boolean boolean类型转换 num = 0; var b1 = Boolean(num); console.log(b1) 转化为数字类 ...

  8. 三种JavaScript 消息框

    prompt 提示框 <html><head><script type="text/javascript">function disp_prom ...

  9. 写入cookie后只显示一次的DIV提示框代码

    <script type="text/javascript"> function cookiesave(n, v, mins, dn, path){ if(n) { i ...

随机推荐

  1. Sallen-Key Active Butterworth Low Pass Filter Calculator

    RC 2nd Order Passive Low Pass Filter The cut-off frequency of second order low pass filter is given ...

  2. python测试开发django-46.xadmin添加action动作

    前言 Action插件在数据列表页面上提供数据选择功能.可以在Action之后专门处理所选数据.批量删除功能作为默认操作提供. action文档 要启用Action,开发人员可以设置Model Opt ...

  3. WHY数学表达式的3D可视化

    WHY数学表达式的3D可视化 很早之前我就有这种想法,将数学表达式的图形显示出来.最近终于实现了这套较为完善的版本,将其代码公布,也为开源做点贡献.首先系统中定义一套脚本语言格式,用于描述数学表达式. ...

  4. vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码

    什么是PHP-CS-Fixer?    它是php-fig组织定义的PHP代码规范,良好的代码规范可以提高代码可读性,团队沟通维护成本    使用它可以按照指定的规范格式化您的PHP代码,此工具不仅可 ...

  5. bug Spring Mvc中Jsp页面获取不到Controller中的变量

    今天遇到了一个奇怪的问题: jsp代码如下: <h1>数据对比${name}</h1> 在controller里面,有赋值: @RequestMapping(value = & ...

  6. Ubuntu11.04安装引导BURG

    时间:11-05-10    BURG是一个漂亮的引导程序,可以代替ubuntu默认的引导. ubuntu11.04安装方法如下: sudo add-apt-repository ppa:n-muen ...

  7. R中统计假设检验总结(一)

    先PS一个:考虑到这次的题目本身的特点 尝试下把说明性内容都直接作为备注写在语句中 另外用于说明的部分例子参考了我的教授Guy Yollin在Financial Data Analysis and M ...

  8. 12C -- DDL日志

    DDL日志和alert日志有相似的格式和行为.但是只包含DDL语句日志.oracle只是为数据库组件提供DDL日志,且需要将参数enable_ddl_logging设置为true. 在DDL日志中,每 ...

  9. 译 5. Spring使用JDBC访问关系数据

    本指南将引导您完成使用Spring访问关系数据的过程.原文阅读 1. 你将构建什么? 您将使用Spring的JdbcTemplate构建一个应用程序来访问存储在关系数据库中的数据. 2. 你需要准备什 ...

  10. Atitit 项目文档规范化与必备文档与推荐文档列表

    Atitit 项目文档规范化与必备文档与推荐文档列表 ===========比较重要的必备文档========== 项目组名单通讯录( 包括项目组,客户沟通人等 需求文档 原型ui文档 开发计划表 项 ...