[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. 在使用过程中,侧边栏的白点和 ...
随机推荐
- destoon_笔记
{mb_substr($shop_type[catname],0,4)} {dsubstr($v['company'],18)} =================================== ...
- asp.net -mvc框架复习(4)-ASP.NET MVC中的约定规则
1.路由规则 using System;using System.Collections.Generic;using System.Linq;using System.Web;using System ...
- linux如何安装java环境
linux安装jdk7步骤: 1.首先使用命令查看linux系统版本号: lsb_release -a 11 2.下载对应的jdk版本,笔者使用的是jdk-7u79-linux-x64.tar.gz: ...
- RAC某节点v$asm_disk查询hang分析处理
主题:RAC某节点v$asm_disk查询hang分析处理 环境:Oracle 11.2.0.3 RAC 故障描述:RAC环境2个节点,节点1查询v$asm_disk正常返回结果,节点2查询v$asm ...
- Android开发之漫漫长途 XIII——Fragment最佳实践
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- python装饰器实现对异常代码出现进行监控
异常,不应该存在,但是我们有时候会遇到这样的情况,比如我们监控服务器的时候,每一秒去采集一次信息,那么有一秒没有采集到我们想要的信息,但是下一秒采集到了, 而后每次的采集都能采集到,就那么一次采集不到 ...
- Spring-事务配置和详解
一.Spring事务配置 在项目开发过程中经常会使用事务来确保数据的一致性.根据网上的资料整理一下在spring中配置事务的几种方式.无论是哪种方式都需要在配置文件中配置连接池和事务管理器,代码如下. ...
- JVM-类的四种载入方式
package org.burning.sport.javase.classloader; public class ClassLoaderMain { public static void main ...
- Mongodb_基本操作UCRD
网站 Mongodb官网:www.mongodb.org 安装包下载 使用文档 Mongodb国内官方网站:www.mongoing.com 数据库概念 有组织的存放数据 按照不同的需求进行查询 数据 ...
- Oracle Sqlload 导入数据
sqlload导入数据具有快,简单,无需校验等方便,多说无益 1 首先,oracle数据库要有这么个表,用来接收数据.我这里这个uuid是序列生成的,当然也可以sqlload导入时候分配uuid -- ...