警报信息的问题



我试图得到"密码丢失"工作时,我不键入相同的密码,我试图得到"hello填充一切"工作时,没有给出答案。

的问题是,它跳过了前两个语句,然后跳转到最后一个警告"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)
}
}

"

使用alarm代替AAAAA

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

似乎您的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)
}

你的文案有问题&粘贴。你有太多不平衡的大括号。如果你想显示消息,你必须把它作为参数发送给函数。

代码如下:

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)
}

相关内容

  • 没有找到相关文章

最新更新