我对窗口层次结构有疑问。当我尝试登录或注册并打开应用程序的主页时,我无法显示其他页面控制台错误:
Warning: Attempt to present on whose view is not in the window hierarchy!
但是当我使用同一用户重新打开我的应用程序时,一切正常。这是创建用户进程后的代码:
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)
})
}
}
这里是调用top函数的函数:
@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)
}
最佳答案
也许你的 rootViewController 正在呈现另一个 ViewController。 您可以尝试:
if let presentedVC = self.presentedViewController {
presentedVC.present(navController, animated: false, completion: nil)
} else {
self.present(navController, animated: false, completion: nil)
}
关于ios - 当我尝试登录或注册我的应用程序时,Swift 窗口层次结构错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58030082/