2017-07-06 38 views
0

我正在Swift上爲一個應用程序創建一個註冊視圖。我想在用戶成功註冊時加載彈出視圖以添加更多數據。我正在使用Parse存儲數據。在解析(SWIFT)上保存數據時打開彈出視圖

我使用這個代碼來保存數據:

@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 { 


       } 


      }) 
     } 
    } 

else語句,我想添加以下代碼:

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

但如果我加載它在它只能在viewDidLoad和didReceiveMemoryWarning之後,如果在保存用戶數據時沒有錯誤,我該如何加載這個彈出窗口?

感謝

回答

0

您的代碼似乎罰款,你忘記了一些語句(調試器應在默認情況下告知給你)前添加隱self聲明。試試這個:

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