【问题标题】:how to show alert message if both user name and password is empty如果用户名和密码都为空,如何显示警报消息
【发布时间】:2019-04-05 04:44:48
【问题描述】:

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

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

请帮忙..

【问题讨论】:

    标签: iphone xcode10 swift4.2


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-05-05
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      相关资源
      最近更新 更多