[Swift]UIKit学习之警告框:UIAlertController和UIAlertView
Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle ofUIAlertControllerStyleAlert.
在Xcode7中使用UIAlertView会报如下警告:
'UIAlertView' was deprecated in iOS 9.0: UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead
Alert Views : Alert views display a concise and informative alert message to the user.
UIAlertController 同时替代了 UIAlertView 和 UIActionSheet,从系统层级上统一了 alert 的概念 —— 即以 modal 方式或 popover 方式展示。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// ViewController.swift import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //创建一个Button let button = UIButton(type: UIButtonType.Custom) //初始化UIButton button.frame = CGRectMake(50, 100, 150, 50) //创建一个CGRect, 设置位置和大小 button.backgroundColor = UIColor.greenColor() //设置背景色 button.setTitle( "点击显示弹窗" , forState: UIControlState.Normal) //设置标题 //传递触摸对象(点击事件) button.addTarget(self, action: "buttonPressed:" , forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(button) } // Action func buttonPressed(sender: UIButton) { showAlertReset() } func showAlertDefault(){ let alertController = UIAlertController(title: "弹窗标题" , message: "Hello, 这个是UIAlertController的默认样式" , preferredStyle: UIAlertControllerStyle.Alert) let cancelAction = UIAlertAction(title: "取消" , style: UIAlertActionStyle.Cancel, handler: nil) let okAction = UIAlertAction(title: "好的" , style: UIAlertActionStyle.Default, handler: nil) let resetAction = UIAlertAction(title: "重置" , style: UIAlertActionStyle.Destructive, handler: nil) alertController.addAction(resetAction) alertController.addAction(cancelAction) alertController.addAction(okAction) self.presentViewController(alertController, animated: true , completion: nil) } func showAlertReset(){ let alertControl = UIAlertController(title: "弹窗的标题" , message: "Hello,showAlertReset " , preferredStyle: UIAlertControllerStyle.Alert) let cancelAction = UIAlertAction(title: "取消操作" , style: UIAlertActionStyle.Destructive, handler: nil) let okAction = UIAlertAction(title: "好的" , style: UIAlertActionStyle.Default, handler: nil) alertControl.addAction(cancelAction) alertControl.addAction(okAction) self.presentViewController(alertControl, animated: true , completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } |
参考:
http://www.jianshu.com/p/86f933850df8
http://blog.csdn.net/xiaowenwen1010/article/details/40108097
[Swift]UIKit学习之警告框:UIAlertController和UIAlertView的更多相关文章
- iOS:提示框(警告框)控件UIAlertView的详解
提示框(警告框)控件:UIAlertView 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能. 类型:typedef NS_ENUM(NSInte ...
- 【swift】用Xib实现自定义警告框(Alert)(安卓叫法:Dialog对话框)
在写这篇博客前,先感谢两篇博客 [如何自定义的思路]:https://www.cnblogs.com/apprendre-10-28/p/10507794.html [如何绑定Xib并且使用]:htt ...
- amazeui学习笔记--js插件(UI增强)--警告框Alert
amazeui学习笔记--js插件(UI增强)--警告框Alert 一.总结 1.警告框基本样式:用am-alert声明div容器, <div class="am-alert" ...
- Swift - 操作表(UIActionSheel)的用法,也叫底部警告框
1,下面创建一个操作表(或叫底部警告框)并弹出显示 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 class ViewController: UIViewC ...
- Bootstrap 学习笔记10 弹出框和警告框插件
隐藏还有2个: 警告框:
- Python+Selenium学习笔记9 - 警告框处理
如下图所示,这种窗口是不能通过前端工具对其进行定位的,这里可以通过switch_to_alert()方法去接受这个弹窗 1 # coding = utf-8 2 3 from selenium imp ...
- bootstrap-巨幕、缩略图、警告框
巨幕: <div class="jumbotron"> <div class="container"> <h1>W3Scho ...
- UIAlertView[警告框] [代理协议型]UIActionSheet [表单视图][代理协议型]
//// ViewController.h// UIAlertViewAndUIActionSheet//// Created by hehe on 15/9/21.// Copyright ...
- SublimeText插件Anaconda如何关闭警告框
之前在学习python的时候,使用了代码编辑器Sublime Text 3并安装了强大的Anaconda插件.瞬间让Sublime Text3变身为Python的IDE. 在使用过程中,侧边栏的白点和 ...
随机推荐
- Nginx负载均衡配置简单配置方法
http://www.jb51.net/article/121235.htm Nginx作为负载均衡服务器,用户请求先到达nginx,再由nginx根据负载配置将请求转发至不同的Web服务器.下面通过 ...
- 怎么解决ERROR in Node Sass does not yet support your current environmen问题?
好久没有重新安装node.js,昨天和小伙伴们一起安装,由于自己是在网上自行下载的node,安装地比较顺利,但另外两个小伙伴用的共享文件夹里自带的node,却是屡次碰到问题,快被逼疯,在运行Vue时总 ...
- Jasper之table报表
这段时间用Jasper画报表,讲真的Jasper IDE真的很难用,网上找很久都没找到用table画的配置方法,以下是直接操作源码画table的方法,不用IDE一样可以做出来(不过样式还是得借助IDE ...
- eclipse 用maven创建web项目
Eclipse 用maven构建web项目 (2013-01-27 11:05:31) 转载▼ 标签: it eclipse maven spring web 杂谈 一.背景介绍 对于初学者,用m ...
- Android 双卡获取当前使用流量在线卡的信息
最近接触了一个项目,需要获取在线流量卡的信息,下面的方式,可以获取大部分手机的正确手机卡信息. 一 获取获取IMEI public static String getDeviced(int solt ...
- linux_快照和克隆
什么是快照? 操作虚拟机时候,想保存当前状态为以后操作失误快速那时保存的系统状态,想当于对系统的版本管理,每个节点之间可以互相切换 什么是克隆? 可以选择快照和当前状态,可选择链接克隆和完整克隆 链接 ...
- ssm打印sql语句
在mybatis配置文件中添加<setting name="logImpl" value="STDOUT_LOGGING"/> <?xml v ...
- form表单action=""的作用
看项目时发现action="",可仍旧提交到后台相关页面了.查了一下,action=""相当于当前页面刷新,不过页面按照form表单提交参数到后台@参考文章
- Linux指令--wc
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 1.命令格式: wc [选项]文件... 2.命令功能: 统计指定文件中的字节数. ...
- android dialog弹出的情况下监听返回键
view = LayoutInflater.from(getActivity()).inflate( R.layout.dialog_tips, null); title2 = (TextView) ...