gpt4 book ai didi

ios - 如何在 if-else 条件语句中使用 AlertController

转载 作者:行者123 更新时间:2023-11-30 10:26:23 25 4
gpt4 key购买 nike

我正在登录 View Controller 中创建一个函数。如果用户密码或电子邮件地址不正确,他会收到一条警告,提示“登录未成功”。但是,如果用户密码和电子邮件匹配,他就可以继续访问仪表板 View Controller 。

 func alert(response:String) {

let alert = UIAlertController(title: "Login Failure", message: "Incorrect Email Address, Phone Number or Password", preferredStyle: .alert)

if response == "Login in not sucessful" {




alert.addAction(UIAlertAction(title:"Okay", style: .cancel,handler:nil))
alert.dismiss(animated: true, completion: nil)

self.present(alert, animated: true, completion: nil)

} else if response == "Login Successful" {


self.performSegue(withIdentifier: "dashboardSegue", sender: self)

}

但是每当我点击“登录”按钮时,我都会收到以下错误之一:

 Warning: Attempt to present <myApp.customTabBar: 0x7fe68a889800> on <myApp.ViewController: 0x7fe68a606f90> while a presentation is in progress!

Warning: Attempt to present <UIAlertController: 0x7fe68b853e00> on myApp.ViewController: 0x7fe68a606f90> while a presentation is in progress!

Warning: Attempt to present <UIAlertController: 0x7fe68b815400> on <myApp.ViewController: 0x7fe68a475240> whose view is not in the window hierarchy!

警报仅显示一次,即使用户的电子邮件和密码不正确,应用程序仍会转到仪表板 View Controller 。我想也许是 if 条件语句。我不知道有什么问题。我检查了其他问题,但我不能完全使用 viewDidAppear 方法,因为我不希望在启动时出现警报。新手,感谢您的帮助!

最佳答案

更改以下代码行将解决您的问题。

alert.addAction(UIAlertAction(title:"Okay", style: .cancel,handler:nil))
alert.dismiss(animated: true, completion: nil)
self.present(alert, animated: true, completion: nil)

alert.addAction(UIAlertAction(title:"Okay", style: .cancel, handler:nil))
self.present(alert, animated: true, completion: nil)

关于ios - 如何在 if-else 条件语句中使用 AlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60017674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com