作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个带有警报 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/
我是一名优秀的程序员,十分优秀!