从中间弹出的 Alert
style: .default => 按钮字体颜色为预设的蓝色
handler: nil => 按下後不触发任何事
let alertController = UIAlertController(title: "alert title", message: "alert message", preferredStyle: .alert)
let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(alertAction)
present(alertController, animated: true, completion: nil)
style: .destructive => 按钮字体颜色为红色
handler: { action in } => 按下後触发 action in 之後的事
let alertController = UIAlertController(title: "alert title", message: "alert message", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .destructive, handler: { action in
//按下OK後会做的事情
print("您按下OK")
}))
present(alertController, animated: true, completion: nil)
由下而上弹出的 alert
按了"确认"的按钮後,执行print ( phone as Any, password as Any )
let controller = UIAlertController(title: "选单", message: "请问你的年纪?", preferredStyle: .actionSheet)
let ages = ["0 - 19", "20 - 39", "40 - 59", "60 - 79", "80 - 99", "100 - 100以上"]
for age in ages {
let action = UIAlertAction(title: age, style: .default) { action in
print(action.title as Any) // print 出按下的按钮名称
}
// 有几个 ages 就有几个按钮。当选项太多时, UIAlertController 会自动变身成可以上下卷动的选单
controller.addAction(action)
}
let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
controller.addAction(cancelAction)
present(controller, animated: true, completion: nil)
明天会介绍:
敬请期待!
>>: 【Day 08】 实作 - 透过 AWS 服务 - AppFlow 把 Google Analytics 资料存放至 AWS 中 ( 1 )
来到了倒数第二天 真是快被榨乾了呢(还真是没料 (┐「﹃゚。)) 但说好写三十篇技术文就是要灌满三十...
JSON模组(Python内建) 说明:主要用来读写JSON档案。 何谓JSON? 说明:JSON全...
这一篇,我想再参考官网的攻略写一篇, 不过内容多增加了一些程序上的处理,以及过拟合(Overfitt...
随着理论的成熟,丛集运算能力的提升,深度神经网路模型逐渐发挥了巨大的影响力。 神经元模型 来自於对动...
DAY11 MongoDB 深入聚合与常见问题 MongoDB 的运算子前面有提到过,那是属於查询用...