昨天的Textfield我们其实也可以改成这样:
@IBAction func changePageAction(_ sender: Any) {
let AlertController = UIAlertController(title: "切换页面?", message: "按下OK後跳转", preferredStyle: .alert)
func option(optionTitle: String, optionStyle: UIAlertAction.Style ,mergehandler: ((UIAlertAction) -> Void)?) {
AlertController.addAction(UIAlertAction(title: optionTitle, style: optionStyle, handler: mergehandler))
}
option(optionTitle: "2" , optionStyle: UIAlertAction.Style.default, mergehandler: { action in
let switchToSecondScreen = SecondFrame()
self.navigationController?.pushViewController(switchToSecondScreen, animated: true)
})
option(optionTitle: "3" , optionStyle: UIAlertAction.Style.default, mergehandler: { action in
let switchToThirdScreen = ThirdFrame()
self.navigationController?.pushViewController(switchToThirdScreen, animated: true)
})
option(optionTitle: "取消" , optionStyle: UIAlertAction.Style.destructive, mergehandler: { action in
})
present(AlertController, animated: true, completion: nil)
当然我们也可以用输入框的方式做:
@IBAction func changePageAction(_ sender: Any) {
let CancelAlertController = UIAlertController(title: "转换页面失败", message: "请重试!", preferredStyle: .alert)
let AlertController = UIAlertController(title: "切换页面?", message: "输入你要跳转的页数", preferredStyle: .alert)
AlertController.addTextField { textField in
textField.placeholder = "page?"
}
let alerOktAction = UIAlertAction(title: "ok", style: .default) {[unowned AlertController] _ in
let page = AlertController.textFields?[0].text
switch page {
case "2":
let switchToSecondScreen = SecondFrame()
self.navigationController?.pushViewController(switchToSecondScreen, animated: true)
case "3" :
let switchToThirdScreen = ThirdFrame()
self.navigationController?.pushViewController(switchToThirdScreen, animated: true)
default:
self.present(CancelAlertController, animated: true, completion: nil)
}
}
let TryagainAlertAction = UIAlertAction(title: "OK", style: .destructive, handler: nil)
let alertCancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
AlertController.addAction(alerOktAction)
AlertController.addAction(alertCancelAction)
CancelAlertController.addAction(TryagainAlertAction)
present(AlertController, animated: true, completion: nil)
}
}
成果:
在完整完善的隐私保护设计之下,也需有个健全的隐私保护法规在背後做支撑,藉由完善法规制度的保护之下,视...
如标题,今天想和大家聊聊权限这东西 权限在Linux是个非常非常重要的东西,如果你一直被termin...
04 - Create PR with default template 在 Github 多人开发...
思考重点 TCP如何确认对方收到消息? 讯息收发中的头部消息变化? 关闭连接操作? 核心知识 封包的...
本来打算一篇写完的,结果居然要分成三篇 XD 前端工具挑选 前端的部分可以搭配框架来建立 比较有名的...