警报信息有问题

时间:2016-10-10 01:05:33

标签: javascript swift xcode

我试图让#34;密码丢失"工作的时候,我不输入相同的密码,我试着让#34; helo填写所有内容"当没有给出答案时工作。

问题在于,它跳过前两个语句,然后一直跳到最后一个警告" AAAAA" ..(对不起代码的第一部分......)

if(userPassword != userPasswordRepeat)
    {           
        displayAlertMessage(alarm: ("password missing"));
        return
    }
    if(userEmail == "" || userPassword == "" || userFirstName == "" || userLastName == "")
    {
        //vis alarm besked 2
        displayAlertMessage(alarm: ("helo fill everyting"));
        return
    }        

}
func displayAlertMessage(alarm:String)
{
    let myAlert = UIAlertController(title: "Alert", message: "AAAAA", preferredStyle: UIAlertControllerStyle.alert);

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)


    myAlert.addAction(okAction);


    self.present(myAlert, animated: true, completion: nil)
}
}

`

3 个答案:

答案 0 :(得分:0)

使用参数alarm代替AAAAA

let myAlert = UIAlertController(title: "Alert", message: alarm, preferredStyle: UIAlertControllerStyle.alert);

答案 1 :(得分:0)

似乎永远不会使用alarm中的displayAlertMessage(alarm:String)字符串,请尝试按照代码

func displayAlertMessage(alarm:String){
   //check alarm valid then use it, otherwise use default hint string
   let hintStr = alarm.characters.count > 0 ? alarm : "AAAAA"

   let myAlert = UIAlertController(title: "Alert", message: hintStr, preferredStyle: UIAlertControllerStyle.alert);

   let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)


   myAlert.addAction(okAction);


   self.present(myAlert, animated: true, completion: nil)
}

答案 2 :(得分:0)

您的副本和版本有问题;糊。你有太多不平衡的花括号。 如果要显示消息,则必须将其作为参数发送给函数。

以下是代码:

if(userPassword != userPasswordRepeat)
    {           
        displayAlertMessage(alarm: "password missing");
        return
    }
    if(userEmail == "" || userPassword == "" || userFirstName == "" || userLastName == "")
    {
        //vis alarm besked 2
        displayAlertMessage(alarm: "helo fill everyting");
        return
    }        


func displayAlertMessage(alarm:String)
{
    let myAlert = UIAlertController(title: "Alert", message: alarm, preferredStyle: UIAlertControllerStyle.alert);

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)


    myAlert.addAction(okAction);


    self.present(myAlert, animated: true, completion: nil)
}