ユーザーがuitextフィールドにテキストを入力しないと、エラーメッセージ(UIAlert)を受け取るサインアップページをコーディングしました。 else(ユーザーがすべてのuitextfieldにテキストを入力した場合)サインアップページがFirebase認証用に表示されます。すぐにUIAlertControllerの前で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ボタンに直接セグを作成しましたので、ボタンを押すたびにセグを実行していました。セグを削除して、サインアップUIビューにサインアップビューを接続して新しいものを作成し、すべてを解決しました –