Swift - 告警提示框(UIAlertController)的用法

来源:互联网 发布:iphone7用不了蜂窝数据 编辑:程序博客网 时间:2024/05/16 07:18

Swift - 告警提示框(UIAlertController)的用法


自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertView和UIActionSheel。下面总结了一些常见的用法:

1,简单的应用(同时按钮响应Handler使用闭包函数)
  
原文:Swift - 告警提示框(UIAlertController)的用法
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
import UIKit
 
class ViewControllerUIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
     
    override func viewDidAppear(animated: Bool){
        super.viewDidAppear(animated)
         
        let alertController = UIAlertController(title: "系统提示",
            message: "您确定要离开hangge.com吗?", preferredStyle: .Alert)
        let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
        let okAction = UIAlertAction(title: "好的", style: .Default,
            handler: {
                action in
                print("点击了确定")
        <code class="swift plain" style="outline: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !import
0 0
原创粉丝点击