2016-10-10 120 views
0

我不明白,如果我做錯了什麼或者它是Swift 3語言。提示信息快速3

我有麻煩:

使用局部變量的 「displayAlertMessage」 其聲明之前。

下面是代碼:

if(userPassword != userPasswordRepeat) 
    { 
     //Vis alarm besked 
     displayAlertMessage(userMessage: "passwords does not match"); 
     return 
    } 
    if(userEmail == "" || userPassword == "" || userFirstName == "" || userLastName == "") 
    { 
     //vis alarm besked 2 
     displayAlertMessage(userMessage: ("Alle fields are requred to be filled")); 
     return 
    } 
+0

'swift' or'java'?... – brso05

+5

'displayAlertMessage'聲明在哪裏? – JAL

+0

你是否面臨密碼匹配代碼的概率? – vaibhav

回答

0

您可以使用此功能:

//MARK: alert message 
    func alertMessage(_ userMessage:String){ 

     let myAlert = UIAlertController(title: "Sorry!", message: userMessage, preferredStyle: .alert) 


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

     myAlert.addAction(okAction) 

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

    } 

,然後用它是這樣的:

self.alertMessage("String you would like to display") 

所以,你的代碼看起來像這樣:

if(userPassword != userPasswordRepeat) 
    { 
     //Vis alarm besked 
     self.alertMessage("Passwords do not match") 
     return 
    } 
    if(userEmail == "" || userPassword == "" || userFirstName == "" || userLastName == "") 
    { 
     //vis alarm besked 2 
     self.alertMessage("All fields are requred to be filled") 
     return 
    } 

希望它能幫助你。

-1
let alertView:UIAlertView = UIAlertView() 
         alertView.title = "Title" 
         alertView.message = "Message" 
         alertView.delegate = self 
         alertView.addButton(withTitle: "OK") 
         alertView.show()