ios - 用户使用 Firebase 注销后根 Controller UINavigationBar 消失

标签 ios swift firebase uinavigationbar

我的 UINavigationBar 遇到了一个小问题。

我有一个初始 Root View Controller (ViewController),后跟 2 个 View Controller (LoginMRNViewController 和 LoginOTPViewController),用于使用一次性密码登录用户。我还使用 NavigationController 在用户登录后将其导航到他/她的主页。 在主页中,我有一个(注销)按钮,可以使用 Firebase 注销用户并将其导航到初始 Root View Controller (ViewController)。

UINavigationBar 的工作方式就像一个魅力,但是,每当用户注销时,他都会导航到初始 Root View Controller (ViewController),但 UINavigationBar 完全消失!

我的注销功能:

@IBAction func logoutPressed(_ sender: Any) {
    do {
        try Auth.auth().signOut()

        self.performSegue(withIdentifier: "goToLoginScreen", sender: self)
        print ("User logged out")
    } catch let error {
        print ("Failed to logout with error", error)
    }
}

这是我的 Storyboard好像。

编辑:

我尝试将其放入 ViewWillAppear 方法中的初始 Root View Controller (ViewController) 和其他 2 个 View Controller (LoginMRNViewController 和 LoginOTPViewController)中,但不幸的是它不起作用。

self.navigationController?.setNavigationBarHidden(false, animated: false)
tabBarController?.tabBar.isHidden = false

这是我的更新方式 Storyboard看起来像。

最佳答案

不要添加另一个 NavigationController 来隐藏后退按钮。

添加navigationItem.setHidesBackButton(true,animated: true)以隐藏后退按钮。

然后在注销时只需添加 self.navigationController?.popToRootViewController(animated: true)

它应该按预期工作。

关于ios - 用户使用 Firebase 注销后根 Controller UINavigationBar 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54699114/

相关文章:

objective-c - 自定义框架中的错误 "No known class method for selector ' Hello :'"

ios - NSUserDefaults 无法检索图像数组

json - Swift 4 可编码 : the keys are Int array in JSON data

swift - 在 firebase 数据库中搜索子子项

objective-c - ARC、非 ARC 和继承

iphone - 在 iPhone App 首次启动时显示信息 imageview

ios - AppCode + swift - 没有代码完成,也没有快速文档

java - 如何在 Firebase RecyclerView 中添加加载进度条

javascript - Angular 5 和 firebase/angularfire,使用键检查键是否存在于另一个表中

ios - Xcode 11.1 错误 : Multiple commands produce