简体   繁体   English

当我从另一个视图选择回到视图时,TabBarController消失了

[英]TabBarController disappears when I segue back to the view from another view

I have a viewController that is embedded in a nav controller. 我有一个嵌入在导航控制器中的viewController。 This nav controller is then embedded in a tab bar controller. 然后将此导航控制器嵌入到选项卡栏控制器中。

I have another viewController that is not supposed to be accessible from the tabBarController. 我有另一个不应从tabBarController访问的viewController。 It should only be accessible from the first viewController using a button. 它只能使用按钮从第一个viewController访问。 From the secondViewController, I made a UIBarButtonItem to move back to the original view. 在secondViewController中,我制作了一个UIBarButtonItem移回原始视图。 From the first view to the second view and vice versa, I used a Storyboard reference to move to and from from the views. 从第一个视图到第二个视图,反之亦然,我使用情节提要参考来在视图之间来回移动。

However, when I move from the first view to the second view, the tab bar controller disappears (like it should). 但是,当我从第一个视图移动到第二个视图时,选项卡栏控制器消失了(应该如此)。 When I move back to the first view, the tab bar controller disappears and I cannot move between tabs anymore. 当我回到第一个视图时,选项卡栏控制器消失,并且无法再在选项卡之间移动。

I tried including: 我试过包括:

self.hidesBottomBarWhenPushed = false

on the first view and 在第一个视图上

self.hidesBottomBarWhenPushed = true

on the second view 在第二个观点

and nothing seems to work. 似乎没有任何效果。 The tab bar controller disappears every time i move from the second view to the first view. 每当我从第二个视图移动到第一个视图时,选项卡栏控制器就会消失。

You are following a wrong hierarchy. 您遵循的是错误的层次结构。 You are actually using seagues to go back and forth. 您实际上是在使用海贼来回走动。 This creates a new instance every time you try to come back to the first controller. 每次您尝试返回第一个控制器时,都会创建一个新实例。

Let's make it clear: 让我们说清楚:

You need to follow the below approach: 您需要遵循以下方法:

1 You have two controllers A and B. 1您有两个控制器A和B。

2 Use self.hidesBottomBarWhenPushed = true in viewDidLoad or viewWillAppear of controller A. 2在控制器A的viewDidLoad或viewWillAppear中使用self.hidesBottomBarWhenPushed = true。

3 Controller A is embedded in a navigation controller which is further embedded in a UITabBarController. 3控制器A嵌入在导航控制器中,该控制器进一步嵌入在UITabBarController中。

Tapping a button in controller A, you need to push to controller B. So you can use segue for this or you can do it programatically like: 点击控制器A中的按钮,您需要按入控制器B。因此,您可以为此使用segue或以编程方式执行此操作,例如:

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

4 Go Back to Controller A on the tap UIBarButtonItem. 4在水龙头UIBarButtonItem上返回至控制器A。 So your code in the action of UIBarButtonItem should be something like: 因此,您在UIBarButtonItem动作中的代码应类似于:

self.navigationController?.popViewController(animated: true)

Remember you should not should segue to go back to the previous controller. 请记住,您不应该搜寻返回上一个控制器。

you should use 你应该使用

 override func viewWillDisappear(_ animated: Bool) {
    self.tabBarController?.tabBar.isHidden = false
}

in that controller where the back button is placed, I am using the exact scenario in one of the my app. 在放置后退按钮的那个控制器中,我正在其中一个应用程序中使用确切的场景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UINavigationBar在另一个视图继续显示时消失了吗? - UINavigationBar disappears when another view segue's to it? 如何从TabbarController选择视图控制器? - How to segue to view controller from TabbarController? 从我的故事板上的另一个视图中获取tabbarcontroller - Get tabbarcontroller from another view on my storyboard 从另一个视图执行 segue 作为全视图 - perform segue as full view from another view 我如何将自己依次返回到另一个视图控制器,然后转发到另一个视图控制器 - How can I Segue back, to a different view controller, and then forward, to another view controller 尝试从一个视图 controller 切换到另一个视图时出错 - Error when trying to segue from one view controller to another 当选择另一个视图时隐藏UISearchController - Hide UISearchController when segue to another view 是否可以从UIView上的UITableViewCell转到另一个视图 - is it possible to segue from a UITableViewCell on a UIView to another view 从ZBar切换到另一个视图时出错 - error to segue from ZBar to another view 从SplitViewController中的MasterViewController发送到另一个View Controller - Segue from the MasterViewController in a SplitViewController to another View Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM