ios - 如何添加警报 View

标签 ios swift uialertcontroller

我希望能够在登录屏幕上添加一个警报 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/

相关文章:

objective-c - 如何从 UIWebView 中删除链接?

函数只能在主线程中调用,为什么呢?

arrays - 从数组中删除重复的 PHAssets?

ios - 在 View 顶部显示警报 Controller ,Swift

ios - UIAlertControllerInterfaceActionGroupView 不明确的布局

ios - UIAlertController 不返回用户输入

iphone - 当我单击 UIButton 时,我试图找出 UITableView 中当前选择了哪些单元格

ios - 滚动时带有 UIButton 的 UITableViewCells 重叠

Objective-C:从字符串中去除 HTML 标签

swift - 从 Storyboard 创建 Swift 代码