swift - 如何修复警报
问题描述
我写了一个函数来输出警报,但它不起作用。
这是功能:
if titleTextField.text.isEmpty == false {
if let result = DataManager.shared.quizController.joinQuiz(id: titleTextField.text) {
switch result {
case .badCode :
self.showErrorAlert(message: "Bad code")
case .joined:
self.showErrorAlert(message: "You are alredy joined")
case .notJoined:
navigationController?.popToRootViewController(animated: true)
我希望这会输出一些警报,但是我根本没有得到任何输出。
解决方案
这是显示警报的简单方法
if titleTextField.text.isEmpty == false {
if let result = DataManager.shared.quizController.joinQuiz(id: titleTextField.text) {
switch result {
case .badCode :
self.showErrorAlert(message: "Bad code")
case .joined:
self.showErrorAlert(message: "You are alredy joined")
case .notJoined:
navigationController?.popToRootViewController(animated: true)
}
}
//function for showing alert message
func showErrorAlert(_ with message: String){
let alert = UIAlertController(title: "", message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "ok", style: .default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}
推荐阅读
- apache-spark - aws emr pyspark 卡在对方付费电话上
- android - setText() inside Fragment inside FrameLayout
- api - 与 MS Graph 和 asp.net Core API 斗争
- r - 如何计算 R 中使用两个栅格堆栈的每个组的最大值?
- tsql - 是否可以检查链接服务器上是否存在 tmp 表?
- flutter - 在customScrollView中滚动到底部时如何检测并运行加载功能
- artifactory - 限制 Jfrog Artifactory 中的快照数量
- ruby - 使用检测 rfid 的外围设备在 Ruby 中创建一个循环
- azure - 重新实现 uniqueString() 哈希 ARM 函数
- java - 每年管理 Java 密钥库更改