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. WinPython

    WinPython   http://winpython.github.io/

  2. C#--WinForm项目主窗体设计

    主窗体基本设置 大小.颜色.去边框.出现的位置 Panel控件 背景图.颜色.布局: Label标签 文本.字体.背景颜色.布局 按钮 布局.文本.字体颜色.背景色. 底部panel绑定控件边框.颜色 ...

  3. CUDA_ERROR_OUT_OF_MEMORY

    E tensorflow/stream_executor/cuda/cuda_driver.cc:1002] failed to allocate 198.83M (208486400 bytes) ...

  4. mac环境下intellij的自定义配置文件位置

    ~/Library/Preferences/IntelliJIdea2017.2/

  5. 关于#progma comment 中库文件相对路径问题

    最近做一个验证程序的对话框编程,因为里面要要用到静态链接库,所以就稍微的学习了下静态链接库知识,学习的过程中感觉到了自己所了解的东西实在是少的可怜,更加坚定了自己要更加上进的决心,要把以前所丢掉的都给 ...

  6. SQL Server连接错误1326

    全新的SQL Server 2017,在2018年末才安装上,不过使用它来管理并不复杂的几张表,占用相对较多服务器资源,确实是有些大材小用. 无论如何,安装还是比较顺利.记得2012年第一次安装SQL ...

  7. pycharm怎么设置代码自动补齐

    代码补全功能在PyCharm上是一流的.默认情况下PyCharm会在你输入的时候给出建议: 由于此功能可有点耗电,你可以通过选择File→Power Save Mode来禁用它.您仍然可以通过Cont ...

  8. Linux中搭建一个ftp服务器详解

    来源:Linux社区  作者:luzhi1024 详解Linux中搭建一个ftp服务器. ftp工作是会启动两个通道:控制通道 , 数据通道在ftp协议中,控制连接均是由客户端发起的,而数据连接有两种 ...

  9. 【Android】详解Android Service

    目录结构: contents structure [+] Service简单概述 Service在清单文件中的声明 Service启动服务 Service绑定服务 扩展Binder类 使用Messen ...

  10. IDEA使用笔记(八)——自动生成 serialVersionUID 的设置

    这个设置比较简单,也有一些博文已经写到了,为什么我还要写哪?(潜台词:因为我想凑一篇博文)我觉得学习,特别是编程学习是需要重复造轮子的,另外,就是加深自己的印象方便自己的查找.还有就是关键点,有些博客 ...