gpt4 book ai didi

ios - UIAlertController 不应显示

转载 作者:行者123 更新时间:2023-11-28 10:19:39 24 4
gpt4 key购买 nike

我正在制作一个带有警报 Controller 的登录应用程序,如果用户没有正确数量的密码字符,则不应让用户继续。当我输入正确的金额时,警报 Controller 弹出,不允许我继续。我的代码中有什么不应该的吗?

func alertDisplay() {

let alertController = UIAlertController(title: "Alert", message: "Five characters or more is required to login", preferredStyle: UIAlertControllerStyle.Alert)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) {ACTION -> Void in
// Does nothing
}
let okAction = UIAlertAction(title: "OK", style: .Default) { action -> Void in
// does nothing also
}
alertController.addAction(cancelAction)
alertController.addAction(okAction)

self.presentViewController(alertController, animated: true, completion: nil)
self.dismissViewControllerAnimated(true, completion: nil)

let allowedChars = 15
let passwordCount = passwordField.text?.characters.count

if passwordCount <= allowedChars {
// allow user to continue if the amount of characters is less than 15
alertController.viewDidAppear(false)

} else {
// allow user to not be able to continue if they have too many characters

alertController.viewDidAppear(true)
}
}

最佳答案

替换:

self.presentViewController(alertController, animated: true, completion: nil)
self.dismissViewControllerAnimated(true, completion: nil)

let allowedChars = 15
let passwordCount = passwordField.text?.characters.count

if passwordCount <= allowedChars {
// allow user to continue if the amount of characters is less than 15
alertController.viewDidAppear(false)

} else {
// allow user to not be able to continue if they have too many characters

alertController.viewDidAppear(true)
}

与:

let allowedChars = 15
let passwordCount = passwordField.text?.characters.count

if passwordCount > allowedChars {
self.presentViewController(alertController, animated: true, completion: nil)
}

关于ios - UIAlertController 不应显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36701016/

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