2017-07-06 10 views
0

私はアプリのSwiftでレジスタビューを作成しています。私は、ユーザーが正常にデータを追加するために登録されたときにポップアップ表示をロードしたい。 Parseを使ってデータを保存しています。私は、データを保存するには、このコードを使用していParse(SWIFT)でデータを保存するときにポップアップビューを開く

let vc = (
     storyboard?.instantiateViewController(
      withIdentifier: "sbPopUpID") 
     )! 
    vc.modalTransitionStyle = .crossDissolve 
    present(vc, animated: true, completion: nil) 

しかし、私はそれをロードした場合にのみ動作します:else文で

@IBAction func registerButtonPressed(_ sender: Any) { 

    if emailTextField.text == "" || usuerTextField.text == "" || password1TextField.text == "" || password2TextField.text == "" { 

     createAlert(title: "Error", message: "Fill all data") 

    } else { 

     if password1TextField.text != password2TextField.text { 

      createAlert(title: "Error", message: "Passwords must be the same") 
     } else { 

      activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) 
      activityIndicator.center = self.view.center 
      activityIndicator.hidesWhenStopped = true 
      activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray 
      view.addSubview(activityIndicator) 
      activityIndicator.startAnimating() 
      UIApplication.shared.beginIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared 

      let user = PFUser() 

      user.username = usuerTextField.text 
      user.email = emailTextField.text 
      user.password = password1TextField.text 

      let acl = PFACL() 

      acl.getPublicWriteAccess = true 

      user.acl = acl 

      user.signUpInBackground(block: { (success, error) in 

       self.activityIndicator.stopAnimating() 
       UIApplication.shared.endIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared 

       if error != nil { 

        var displayErrorMessage = "Please try again later." 

        let error = error as NSError? 

        if let errorMessage = error?.userInfo["error"] as? String { 

         displayErrorMessage = errorMessage 

        } 

        self.createAlert(title: "Signup Error", message: displayErrorMessage) 

       } else { 


       } 


      }) 
     } 
    } 

を、私はこのコードを追加したいですviewDidLoadとdidReceiveMemoryWarningの後で、ユーザデータを保存して間違いがない場合、このPop Upをロードするにはどうしたらいいですか?

あなたのコードは罰金だおかげ

答えて

0

、あなただけのいくつかのステートメント(デバッガはデフォルトであなたにこのことを助言すべきである)の前に暗黙のself宣言を追加するのを忘れ。試してみてください:

let vc = self.storyboard!.instantiateViewController(withIdentifier: "sbPopUpID") 
vc.modalTransitionStyle = .crossDissolve 
self.present(vc, animated: true) 
関連する問題