2017-04-02 6 views
-4

私は下から15番目と16番目の行にエラーを受信し続けることが私に語った:。「未解決識別子 『myAlert&okAction』の使用

『未解決識別子の使用『myAlert & okAction』』

誰でも助けることができるならば、それははるかに高く評価されるだろう

コード:

import UIKit 

class RegisterPageViewController: UIViewController { 
    @IBOutlet weak var userNameTextField: UITextField! 
    @IBOutlet weak var userPhoneTextField: UITextField!; 
    @IBOutlet weak var userPasswordTextField: UITextField!; 
    @IBOutlet weak var userConfirmPasswordTextField: UITextField!; 
    @IBOutlet weak var userPlugTextField: UITextField!; 

    @IBAction func RegisterButtonTapped(_ sender: Any) { 
     let userName = userNameTextField.text; 
     let userPhone = userPhoneTextField.text; 
     let userPassword = userPasswordTextField.text; 
     let userConfirmPassword = userConfirmPasswordTextField.text; 
     let userPlug = userPlugTextField.text; 

     // Check for empty fields 
     if(userName!.isEmpty || userPhone!.isEmpty || userPassword!.isEmpty || userConfirmPassword!.isEmpty || userPlug!.isEmpty) 
     { 
      displayMyAlertMessage(userMessage: "All fields are required") 

      return; 
     } 

     // check if passwords match 
     if(userPassword != userConfirmPassword) 
     { 
     // Display an alert message 
      displayMyAlertMessage(userMessage: "Passwords do not match") 
      return; 
     } 

     // Store data 
     UserDefaults.standard.set(userName, forKey: "userName") 
     UserDefaults.standard.set(userName, forKey: "userPhone") 
     UserDefaults.standard.set(userName, forKey: "userPassword") 
     UserDefaults.standard.set(userName, forKey: "userPlug") 
     UserDefaults.standard.synchronize(); 

     // Display alert message with confirmation 
     _ = UIAlertController(title:"Alert", message:"Registration is successful. Thank you!", preferredStyle: UIAlertControllerStyle.alert); 

     _ = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default){ action in 
      self.dismiss(animated: true, completion:nil) 
     } 

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

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

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

     myAlert.addAction(okAction); 

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

_ = UIAlertController(title:"Alert", message:"Registration is successful. Thank you!", preferredStyle: UIAlertControllerStyle.alert); _ = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default){ action in self.dismiss(animated: true, completion:nil) } 

を交換してください:使用していません ' ; '素早く、それらはオプションです –

+0

' if'ステートメントにかっこは必要ありません。 – rmaddy

+0

'RegisterButtonTapped'メソッドの警告コードを' displayMyAlertMessage'メソッドの呼び出しで置き換えてみませんか? – rmaddy

答えて

0

これらの2つのオブジェクトは、スコープ外で参照しようとしているため、表示できません。それらのスコープは、それらが定義されている機能です。

わからないあなたは

displayMyAlertMessage(userMessage:) 
0

を持っている場合は、しかし、すべてでそれらの2つの行を持っている理由だけで提案

let myAlert = UIAlertController(title:"Alert", message:"Registration is successful. Thank you!", preferredStyle: UIAlertControllerStyle.alert); 

    let okAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default){ action in 
     self.dismiss(animated: true, completion:nil) 
    } 
関連する問題