2017-12-16 21 views
0

작성중인 응용 프로그램에 로그인 기능이 있는데 정상적으로 작동하는 것처럼 보입니다. 나는 Parse를 사용한다. 다음은 로그인 기능입니다. 사용자 이름 또는 암호 텍스트 필드가 비어있는 경우이를이 경고가 생성하는 경우Swift 3 이전보기로 돌아 가기 컨트롤러

@IBAction func login(_ sender: AnyObject) { 

    if self.userName.text == "" || self.password.text == "" { 
     self.createAlert(title: "Login Error", message: "Please make sure all fields are filled in") 
    }else{ 
     PFUser.logInWithUsername(inBackground: userName.text!, password: password.text!) { (user, error) in 

     self.activityIndicator.stopAnimating() 
     UIApplication.shared.endIgnoringInteractionEvents() 



     if error != nil { 
      var displayErrorMessage = "Please try again later." 

      if let errorMessage = (error! as NSError).userInfo["error"] as? String { 

       displayErrorMessage = errorMessage 
      } 

      self.createAlert(title: "Signup Error", message: displayErrorMessage) 
     }else{ 
      print("logged in") 

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

     } 

     } 

    } 

} 

그래서 첫 번째 체크 확인합니다. 처음 앱을 시작하면 매력처럼 작동합니다. 그러나 사용자와 로그인하여 로그 아웃 할 때 사용자 이름과 비밀번호가 비어있는 로그인 화면으로 리디렉션됩니다. 그리고 로그인을 클릭하고 "모든 입력란이 모두 입력되어 있는지 확인하십시오"라는 적절한 경고를받습니다.이를 해제하면 로그인이 성공한 것처럼 자동으로 수행합니다. 아무도 나를 도울 수 있습니까? 문, 제대로 그래서 그 점에서의 있으리라 믿고있어 일을하면 내가 처음 후에 createAlert 방법을 제거하면

func createAlert(title: String, message: String) { 

    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) 

    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in 
     self.dismiss(animated: true, completion: nil) 
    })) 

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

} 

:

@IBAction func logOut(_ sender: AnyObject) { 

    PFUser.logOut() 
    performSegue(withIdentifier: "logOutSeg", sender: self) 

} 

또한,이 내 생성 경고 기능입니다.

+1

로그인 화면을 훑어보고 ok 액션에서 self.dismiss를 수행하고 있는지 궁금합니다. 해고가 단절을 취소 할 수 있습니까? 그들이 로그 아웃하지만 난 self.dismiss 작업을 – ryantxr

+0

: alert.addAction – tee

+1

페이지를 호출하고있어 어디 어디에서나 볼 수 없습니다 때 로그인 화면에 SEGUE을 @ryantxr – ryantxr

답변

1

그것은 SEGUE를 수행하여 첫 번째 로그 화면으로 오는 경우, 처음 2 화면에서 로그 아웃하고,이 발생할 수 있습니다. 그래서 비어있는 사용자 이름과 비밀 번호를 얻을 수 있습니다. self.dismiss(animated: true, completion: nil)을 호출하여 로그인 화면에서 alertviewcontroller를 닫으면 현재보기 컨트롤러가 닫힙니다. 로그 아웃 한 후 segue를 수행하는 대신 로그인 된 화면 (두 번째 화면)을 닫으십시오.

+0

이 좋아 내가 기본적으로 self.dismiss 제거있어 감사합니다 그리고 그것은 작동합니다! – tee