2017-04-01 2 views
0

Ich habe Probleme mit zwei Segmenten, aber da ich die gleiche Logik bei der Umsetzung von jedem dieser Segmente verwendet habe, werde ich fortfahren und alles zu einem zusammenfassen Frage. Grundsätzlich versuche ich ein Segment nach der Durchführung createUser Funktion mit Firebase und nach der Durchführung login Funktion auch von Firebase durchgeführt, jedoch, wenn die SignUp und Login Tasten angeklickt scheint es scheint keine Antwort auf das Segment aufgerufen wird zu initialisieren. Unten ist der Code für jede der @IBActionsSegue nach neuer Benutzererstellung mit Firebase nicht ausgeführt -Swift

@IBAction func signUpComplete(_ sender: Any) { 
    FIRAuth.auth()?.createUser(withEmail: signUpEmailField.text!, password: signUpPasswordField.text!, completion: { (user: FIRUser?, error) in 
     if self.signUpEmailField.text == "" || self.signUpPasswordField.text == "" { 
       let alert = UIAlertController(title: "Oops!", message: "A valid E-mail and Password are Required", preferredStyle: UIAlertControllerStyle.alert) 
       alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) 
        self.present(alert, animated: true, completion: nil) 



     if FIRAuthErrorCode.errorCodeEmailAlreadyInUse != nil { 

      let emailExists = UIAlertController(title: "Oops!", message: "A user with this E-Mail already exists!", preferredStyle: UIAlertControllerStyle.alert) 
      emailExists.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) 
      self.present(emailExists, animated: true, completion: nil) 


      } 

     else { 

      DispatchQueue.main.async() { 
       self.performSegue(withIdentifier: "signUpSucceededSegue", sender: self) 
      } 
      } 

      } 
     }) 
} 

und

@IBAction func loginButton(_ sender: Any) { 

    FIRAuth.auth()?.signIn(withEmail: emailLoginField.text!, password: passwordLoginField.text!, completion: { (user: FIRUser?, error) in 
      if self.emailLoginField.text == "" || self.passwordLoginField.text == ""{ 

       let alert = UIAlertController(title: "Alert", message: "E-Mail is Required", preferredStyle: UIAlertControllerStyle.alert) 
       alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) 
       self.present(alert, animated: true, completion: nil) 

      if FIRAuthErrorCode.errorCodeUserNotFound != nil { 

       let invalidLogin = UIAlertController(title: "Alert", message: "E-Mail/Password Incorrect", preferredStyle: UIAlertControllerStyle.alert) 
       invalidLogin.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) 
       self.present(invalidLogin, animated: true, completion: nil) 

      } 

     else{ 


       DispatchQueue.main.async() { 

        self.performSegue(withIdentifier: "loginSucceededSegue", sender: self) 

       } 

      } 


     } 
    }) 

auf den ersten Blick eklatante logische Fehler gibt oder gibt es einen besseren Weg, um einen Übergang in diese Funktionen zu implementieren?

Antwort

1
  • einbetten eine Navigation Controller zu den ersten Blick auf das Storyboard
  • Dann diesen Code Versuchen Sie es mit: -

    @IBAction func signUpComplete(_ sender: Any) { 
    
    
    if self.signUpEmailField.text == "" || self.signUpPasswordField.text == "" { 
    
        let alert = UIAlertController(title: "Oops!", message: "A valid E-mail and Password are Required", preferredStyle: UIAlertControllerStyle.alert) 
        alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) 
        self.present(alert, animated: true, completion: nil) 
    
    }else{ 
    
        FIRAuth.auth()?.createUser(withEmail: self.signUpEmailField!.text, password: self.signUpPasswordField!.text, completion: { (user, err) in 
    
         if let ErrorCode = FIRAuthErrorCode(rawValue: err!._code){ 
    
          switch ErrorCode { 
    
          case .errorCodeEmailAlreadyInUse : let emailExists = UIAlertController(title: "Oops!", message: "A user with this E-Mail already exists!", preferredStyle: UIAlertControllerStyle.alert) 
                   emailExists.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) 
                   self.present(emailExists, animated: true, completion: nil) 
    
                   break 
    
          default      : break 
    
          } 
    
         }else{ 
    
          let nextView = self.navigationController!.storyboard!.instantiateViewController(withIdentifier: "signUpSucceededSegue") 
          self.navigationController!.pushViewController(nextView, animated: true) 
    
         } 
        }) 
        } 
    } 
    

Dann Ihren anderen Code-Block in ähnlicher Art und Weise verändern, .

Verwandte Themen