ios - 快速导航栏行为

标签 ios swift uiviewcontroller

我有三个 View Controller ,它们嵌入在导航 Controller 中。

架构如下: enter image description here

我想从第一个 View Controller 中隐藏导航栏。

为此我使用

navigationController?.setNavigationBarHidden(true, animated: true)

在 viewdidload 方法中(对于第一个 Controller )。 同样用于其他两个 Controller ,但使用 false 参数来启用导航栏。

当我加载应用程序时 - 一切正常,NB 被禁用,当我转到第二个 Controller 时也一切正常 - 它已启用。但!当我按下第二个 Controller 的导航栏上的后退按钮并将用户发送到第一个 Controller 时 - 那里启用了导航栏。

当我们返回到 Controller 时,是否应该使用一个特殊的方法?谁能给我解释一下?非常感谢您的帮助。

最佳答案

当您按下后退按钮时,您的 View Controller viewDidLoad 方法不会再次调用(因为 Controller 未重新创建)并且导航栏将具有与您返回之前相同的状态。

为了更新显示的每个 View Controller 的导航栏,您必须在 viewWillAppear 方法而不是 viewDidLoad 中更新它。

关于ios - 快速导航栏行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38813223/

相关文章:

ios - JSON 数据 - 完成处理程序

ios - Objective C 中方法名称的命名约定

iphone - 切换 ViewControllers,但没有任何反应?

iphone - 查看我的应用程序的文件夹中有哪些文件

ios - 从 cocoa pod 导入模块有错误,但仍然能够构建项目

ios - Swift 中 iOS 8 中的 startBrowsingForNearbyPlayersWithHandler()

Swift - 没有全局访问权限的单例

swift - 如何在 swift 中为 UIVIew 制作曲线顶部?

ios - 从一个 View Controller 向另一个 View Controller 发出委托(delegate)调用

ios - 如何在不同的 UIViewController 之间传递数据?