사용자가 uitextfield에 텍스트를 입력하지 않으면 오류 메시지 (UIAlert)가 수신되는 가입 페이지를 코딩했습니다. 그렇지 않으면 (사용자가 모든 uitextfield에 텍스트를 입력하면) 가입 페이지가 Firebase 인증에 표시됩니다.신속히 UIAlertController 이전에 segue가 수행되었습니다.
내 코드에서 사용자는 인증이 성공적으로 완료된 경우에만 로그인 페이지로 이동하고 그렇지 않은 경우 알림 메시지가있는 가입 페이지에 남아 있어야합니다.
문제 - 내 코드는 경고 메시지를 생성 할 수 있지만 오류가 발생해도 사용자가 로그인 페이지를 자동으로 가져 오는 것과 같은 시간입니다. 이는 사용자가 로그인 페이지, 즉 경고 메시지에 관계없이 방향을 풀어주는 세그 (segue)를 수행한다는 것을 의미합니다.
왜 이런 일이 일어날 수 있습니까?
@IBAction func registerPressed(_ sender: Any) {
if nameText.text!.isEmpty || genderText.text!.isEmpty || countryText.text!.isEmpty || yourSchool.text!.isEmpty || yourClass.text!.isEmpty {
print("Please fill all fields") //my code is printing this error
//alert message popup - my code is ble to produce this alert but same it is performing segue and taking user to signin page
//ideally, i want user to be in signup page unless all criteria meet
let alertController = UIAlertController(title: "Error", message: "Please fill all fields", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action:UIAlertAction) in
print("Okay")
}))
let alertWindow = UIWindow(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindowLevelAlert
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(alertController, animated: true, completion: nil)
}
else {
Auth.auth().createUser(withEmail: yourEmail.text!, password: yourPassword.text!) { (user, error) in
if error != nil {
///print errror message
let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action:UIAlertAction) in
print("Okay")
}))
let alertWindow = UIWindow(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindowLevelAlert + 1;
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(alertController, animated: true, completion: nil)
}
else {
print("You have successfully signed up")
self.performSegue(withIdentifier: "JoinUs2SignPage", sender: self)
//updating user information
let userID = Auth.auth().currentUser!.uid
let usertype: String = "Student"
self.ref.child("users").child(userID).setValue(["usertype": usertype ,"username": self.nameText.text!, "usergender": self.genderText.text!, "usercountry": self.countryText.text!, "userschool": self.yourSchool.text!, "userclass": self.yourClass.text!,])
}
}
}
}
당신은 절대적으로 정확하지만 난 내 코드의 미친 부분을 사용 해달라고하면 그것은 나에게 선물하는 즉, 시도를 오류를 줄 것이다 그보기 창 계층 구조에없는 UIAlertController! 그래서 나는 재즈적인 것들을 사용해야했던 오류를 피했다. 선택의 여지가 없다. –
붉은 깃발이 있어야한다. 이 작업을 수행하는보기 컨트롤러가 창 계층 구조에없는 경우 설치 프로그램에 심각한 문제가있는 것입니다. 여기서 귀하의 코드는 "재즈적인"것이 아니라 더 큰 문제를 숨기고있는 해킹입니다. –
당신은 절대적으로 맞았습니다. 나는 모든 것을 초래 한 어리석은 실수를하고있었습니다. IBAction 버튼에 직접 segue를 만들었습니다. 버튼을 누를 때마다 아무 것도 상관없이 segue를 수행하고있었습니다 ... segue를 삭제하고 로그인보기 UI보기에 연결 한 새로운 것을 작성하여 모든 것을 해결했습니다. –