gpt4 book ai didi

ios - UIAlert 突然停止工作?

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

我的代码曾经运行良好,但由于某种原因今天运行它,它执行了不同的任务。我基本上试图在用户的用户名、电子邮件或密码很短的情况下显示警报,否则将发出注册完成的警报,然后转到下一个 View 。但是现在,一旦我单击“提交”,它就会转到下一个 View ,忽略警报。这是代码:

@IBAction func signUp(_ sender: Any) {        
// Validate the text fields
if username!.count < 5 {
let alert = UIAlertController(title: "Invalid", message: "Username must be greater than 5 characters", preferredStyle: UIAlertControllerStyle.alert)
let action = UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)


} else if password!.count < 8 {
let alert = UIAlertController(title: "Invalid", message: "Password must be greater than 7 characters", preferredStyle: UIAlertControllerStyle.alert)
let action = UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)

} else if email!.count < 8 {
let alert = UIAlertController(title: "Invalid", message: "Email must be greater than 7 characters", preferredStyle: UIAlertControllerStyle.alert)
let action = UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)

} else {
let alert = UIAlertController(title: "Success", message: "Account has been created, an email will be sent shortly", preferredStyle: UIAlertControllerStyle.alert)
let action = UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: {
action in
self.performSegue(withIdentifier: "signUpDone", sender: self)
})
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
}

正如你所看到的,我在句柄中有一个segue“signUpDone”,它告诉它只转到下一个完成 View 。但由于某种原因,它会忽略所有 if 语句,而只是进入下一个 View ,而没有任何条件警报或成功警报。我收到一条控制台信息,上面写着“警告:尝试呈现不在窗口层次结构中的 View !”

我还没有接触过代码,但奇怪的是,当我今天尝试运行它时,就会发生这种情况。可能是什么问题呢?

最佳答案

事实证明,segue 直接从按钮连接到 View ,而不是 View 到 View ,这迫使按钮立即转到 View ,而忽略 if 语句!

关于ios - UIAlert 突然停止工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47760091/

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