如果用户名和密码均为空,如何显示警报消息

时间:2018-10-31 23:10:46

标签: iphone xcode10 swift4.2

如何显示警报消息...如果用户名和密码均为空。.

第一拳工作正常...如果电子邮件文本字段为空...请输入您的电子邮件ID并显示警报消息...并且密码也有效... 但是,如果用户名和密码均为空,则显示类似...的消息,请输入您的电子邮件ID

    if textFieldEmailOutlet.text == "" {
        GenericFunctions.showAlert(title: "Alert", message: "Please enter your email id")
    }else if textFieldPasswordOutlet.text == ""{
        GenericFunctions.showAlert(title: "Alert", message: "Please enter your password")
    }else if (self.textFieldEmailOutlet.text == "") || (self.textFieldPasswordOutlet.text == ""){
        GenericFunctions.showAlert(title: "Alert", message: "Please enter your email id & password")
    }

请帮助。

1 个答案:

答案 0 :(得分:0)

您的逻辑相反。一旦到达第一个if语句,它就成立,因为该电子邮件丢失了。您需要颠倒您的陈述以先检查两者。您还设置了它来检查 电子邮件或密码是否为空。

if (self.textFieldEmailOutlet.text == "") && (self.textFieldPasswordOutlet.text == ""){
        GenericFunctions.showAlert(title: "Alert", message: "Please enter your email id & password")
    }else if textFieldPasswordOutlet.text == ""{
        GenericFunctions.showAlert(title: "Alert", message: "Please enter your password")
    }else if textFieldEmailOutlet.text == ""{
        GenericFunctions.showAlert(title: "Alert", message: "Please enter your email id")
    }

这将检查电子邮件和密码是否丢失,并提供您想要的结果。但是,如果其中一个已填写,它将使第一个if子句失败并检查是否有密码。如果有密码,它将继续检查在逻辑上失败的电子邮件地址,并发送有关需要电子邮件地址的警报。