[英]Swift window hierarchy error when I try to login or sign up in my app?
I have question about window hierarchy.我对 window 层次结构有疑问。 When I try to login or sign up and open the home page of app, I can't present other pages console error give that:当我尝试登录或注册并打开应用程序的主页时,我无法显示其他页面控制台错误给出:
Warning: Attempt to present on whose view is not in the window hierarchy!警告:尝试呈现不在 window 层次结构中的视图!
But when I re-open my app with same user everything working correctly.但是当我用同一个用户重新打开我的应用程序时,一切正常。 Here the code which is after create user process:这里是创建用户进程之后的代码:
func createUser(withEmail email: String, password: String, username: String) {
Auth.auth().createUser(withEmail: email, password: password) { (result, error) in
if let error = error {
print("Failed to sign user up with error: ", error.localizedDescription)
return
}
guard let uid = result?.user.uid else { return }
let values = ["E-mail": email, "Kullanıcı Adı": username]
Database.database().reference().child("users").child(uid).updateChildValues(values, withCompletionBlock: { (error, ref) in
if let error = error {
print("Failed to update database values with error: ", error.localizedDescription)
return
}
let layout = UICollectionViewFlowLayout()
let homeController = HomeController(collectionViewLayout: layout)
let navController = UINavigationController(rootViewController: homeController)
self.present(navController, animated: false, completion: nil)
})
}
}
here the function which call top function:这里的 function 调用顶部 function:
@objc func handleSignUp() {
guard let email = emailTextField.text else { return }
guard let password = passwordTextField.text else { return }
guard let username = usernameTextField.text else { return }
createUser(withEmail: email, password: password, username: username)
}
Maybe your rootViewController is presenting another ViewController.也许您的 rootViewController 正在呈现另一个 ViewController。 You can try:你可以试试:
if let presentedVC = self.presentedViewController {
presentedVC.present(navController, animated: false, completion: nil)
} else {
self.present(navController, animated: false, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.