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

how to show alert message if both user name and password is empty

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

拳头两个工作正常...如果电子邮件文本字段为空...它会显示警告消息,请输入您的电子邮件 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")
    }

请帮忙..

你的逻辑反了。一旦它遇到第一个 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 子句失败并检查是否有密码。如果有密码,它将继续检查电子邮件地址(逻辑上)失败并发送有关需要电子邮件地址的警报。