自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertView和UIActionSheel。下面总结了一些常见的用法(
本文代码都已更新至Swift3)
1,简单的应用(同时按钮响应Handler使用闭包函数)
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
|
import UIKit
class ViewController : UIViewController {
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 ( "点击了确定" )
|
请发表评论