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的更多相关文章

  1. iOS:提示框(警告框)控件UIAlertView的详解

    提示框(警告框)控件:UIAlertView   功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能.   类型:typedef NS_ENUM(NSInte ...

  2. 【swift】用Xib实现自定义警告框(Alert)(安卓叫法:Dialog对话框)

    在写这篇博客前,先感谢两篇博客 [如何自定义的思路]:https://www.cnblogs.com/apprendre-10-28/p/10507794.html [如何绑定Xib并且使用]:htt ...

  3. amazeui学习笔记--js插件(UI增强)--警告框Alert

    amazeui学习笔记--js插件(UI增强)--警告框Alert 一.总结 1.警告框基本样式:用am-alert声明div容器, <div class="am-alert" ...

  4. Swift - 操作表(UIActionSheel)的用法,也叫底部警告框

    1,下面创建一个操作表(或叫底部警告框)并弹出显示 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 class ViewController: UIViewC ...

  5. Bootstrap 学习笔记10 弹出框和警告框插件

    隐藏还有2个: 警告框:

  6. Python+Selenium学习笔记9 - 警告框处理

    如下图所示,这种窗口是不能通过前端工具对其进行定位的,这里可以通过switch_to_alert()方法去接受这个弹窗 1 # coding = utf-8 2 3 from selenium imp ...

  7. bootstrap-巨幕、缩略图、警告框

    巨幕: <div class="jumbotron"> <div class="container"> <h1>W3Scho ...

  8. UIAlertView[警告框] [代理协议型]UIActionSheet [表单视图][代理协议型]

    ////  ViewController.h//  UIAlertViewAndUIActionSheet////  Created by hehe on 15/9/21.//  Copyright ...

  9. SublimeText插件Anaconda如何关闭警告框

    之前在学习python的时候,使用了代码编辑器Sublime Text 3并安装了强大的Anaconda插件.瞬间让Sublime Text3变身为Python的IDE. 在使用过程中,侧边栏的白点和 ...

随机推荐

  1. qq客服代码实现过程

    引入css,jsimages,将index.html中的qq聊天代码部分和返回顶部-部分放在head.html文件中, 将文中圈中部分删除,否则影响整个页面的样式:

  2. Linux文件

    Linux文件类型 对于内核而言,所有打开的文件都是通过文件描述符引用(FD),文件描述符是一个非负整数,当打开现有问价或创建一个新文件时,内核向进程返回一个文件描述符. 按照惯例,shell把文件描 ...

  3. CCF系列之相反数(201403-1)

    试题名称: 相反数 试题编号: 201403-1时间限制: 1.0s 内存限制: 256.0MB 问题描述 有 N 个非零且各不相同的整数.请你编一个程序求出它们中有多少对相反数(a 和 -a 为一对 ...

  4. Mac下用SSH连接远程Linux或Mac服务器

    1.打开Mac终端 2.切换到root登录 输入命令:sudo -i,然后输入本机密码 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px &qu ...

  5. c语言统计一个文件中的单词,字符和行数

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  6. C语言知识点总结

    本文采用思维导图的方式撰写,更好的表述了各知识点之间的关系,方便大家理解和记忆.这个总结尚未包含C语言数据结构与算法部分,后续会陆续更新出来,文中有漏掉的知识点,还请大家多多指正.

  7. 如何修改nexus的端口号

    1. Maven仓库:放置所有JAR文件(WAR,ZIP,POM等等)的地方,所有Maven项目可以从同一个Maven仓库中获取自己所需要的依赖JAR,这节省了磁盘资源. 简言之,Maven仓库能帮助 ...

  8. java常用类--系统相关

    java提供了System类和Runtime类来与程序的运行平台进行交互. System类 System类代表java程序的运行平台,程序不能创建这个类的对象,System类提供了一些类field和方 ...

  9. JDBC (五)

    1 使用dbutils进行一对多.多对多的开发 1.1 准备 mysql驱动的pom.xml <!-- https://mvnrepository.com/artifact/mysql/mysq ...

  10. Div+Css画太极图源代码

    <!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>D ...