我编写了一个输出警报的功能,但是它不起作用。
功能如下:
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)
我希望这会输出一些警报,但是我什么也没得到。
答案 0 :(得分:0)
这是显示警报的简单方法
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)
}