简体   繁体   English

当我尝试登录或注册我的应用程序时,Swift window 层次结构错误?

[英]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.

相关问题 当我尝试登录注册用户并通过解析启用推送通知时,我的应用程序崩溃 - My app crashes when I try to log sign up a user and enable push notifications through parse 当我已经在appDelegate.swift中使用Google登录时,如何将Facebook登录信息集成到我的ios应用程序中? - how can I integrate facebook login to my ios app when I already have google sign in in appDelegate.swift? 如何使用Swift将注册页面添加到我的Parse应用程序中? - How do I add a sign up page into my Parse app with Swift? 我尝试编译我的应用程序时出现错误 - Im getting a error when I try and compile my app swift - 使用 Apple 登录“注册未完成”错误 - swift - Sign in With Apple "Sign Up not completed" error 错误消息:其视图不在窗口层次结构中-Swift - Error message: whose view is not in the window hierarchy - Swift 当我尝试呈现视图时,出现此警告“试图呈现其视图不在窗口层次结构中的ViewController” - I got this warning “attempt to present ViewController whose view is not in the window hierarchy” when I try to present a view 当我尝试在Swift中对动作进行排序时,为什么仍会收到此错误? - Why do I keep getting this error when I try to sequence my actions in Swift? 当我向NavigationController提出“其视图不在窗口层次结构中!”错误 - When I present to a NavigationController “whose view is not in the window hierarchy!” error 在应用商店上发布应用时,为什么会出现代码签名错误? - Why do I get a code sign error when I publish my app on app store?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM