ios - 当我从另一个 View 返回 View 时 TabBarController 消失

标签 ios swift uitabbarcontroller segue

我有一个嵌入在导航 Controller 中的 viewController。然后将该导航 Controller 嵌入到选项卡栏 Controller 中。

我有另一个不应从 tabBarController 访问的 viewController。它应该只能从第一个 viewController 使用按钮访问。在 secondViewController 中,我制作了一个 UIBarButtonItem 以移回原始 View 。从第一个 View 到第二个 View ,反之亦然,我使用 Storyboard 引用在 View 之间移动。

但是,当我从第一个 View 移动到第二个 View 时,选项卡栏 Controller 消失了(就像它应该的那样)。当我回到第一个 View 时,标签栏 Controller 消失了,我无法再在标签之间移动。

我试过包括:

self.hidesBottomBarWhenPushed = false

在第一个 View 上

self.hidesBottomBarWhenPushed = true

在第二个 View 上

似乎没有任何效果。每次我从第二个 View 移动到第一个 View 时,标签栏 Controller 都会消失。

最佳答案

您遵循的是错误的层次结构。您实际上是在使用 seagues 来回移动。每次您尝试返回第一个 Controller 时都会创建一个新实例。

让我们说清楚:

您需要遵循以下方法:

1您有两个 Controller A 和 B。

2 在 Controller A的viewDidLoad或viewWillAppear中使用self.hidesBottomBarWhenPushed = true。

3 Controller A 嵌入到导航 Controller 中,导航 Controller 进一步嵌入到 UITabBarController 中。

点击 Controller A 中的按钮,您需要推送到 Controller B。因此您可以为此使用 segue,或者您可以通过编程方式进行操作,例如:

let controllerB = B()
A.navigationController?.pushViewController(controllerB, animated: true)

4 返回到点击 UIBarButtonItem 上的 Controller A。所以你在 UIBarButtonItem Action 中的代码应该是这样的:

self.navigationController?.popViewController(animated: true)

请记住,您不应该继续返回到之前的 Controller 。

关于ios - 当我从另一个 View 返回 View 时 TabBarController 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57689589/

相关文章:

ios - 我要怎么做才能放在Apple Maps的巴士位置?

ios - CLLocationCoordinate2D 两点之间的距离

ios - SCNShadable - 改变纹理的变量和样本

json - 在 Swift 中解析 json blob 字段

ios - 无法使用 UISlider 降低 CIVignette 效果

ios - Storyboard刷新问题 Xcode

ios - Swift:CGPathRelease 和 ARC

ios - UITabBarController 中的 UINavigationController 中的 UITableView,不需要的底部工具栏

ios - UITabBarController 中更多项目的自定义图像和/或标题

objective-c - UITabBarController "want full screen"设置