我希望能够在登录屏幕上添加一个警报 View ,当提交的信息不正确时,显示“用户名/密码不正确”。我正在使用 Swift 2。我对学习代码还是新手,不确定如何添加此操作。
最佳答案
只需使用此代码即可显示警报:
func wrongLogin(input: String) {
var alert = UIAlertController(title: "Incorrect", message: "The \(input) is wrong. Try again.", preferredStyle: UIAlertControllerStyle.Alert)
//add a cancel button
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Cancel, handler: nil))
// Show it
showViewController(alert, sender: self)
}
然后在调用时只需传入用户名或密码即可。
您可以像这样 wrongLogin("password")
或 wrongLogin("username")
有关更多信息,请参阅此 answer .
希望有帮助,朱利安。
关于ios - 如何添加警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34385277/