Keep TabBar When Switching to Another View Controller

I have such a storyboard

-> NavigationController β†’ LoginView β†’ TabBarController β†’ VC1 β†’ VC2

I was not able to make the "transition" from VC1 to VC2, while maintaining the tab bar.

I tried the following:

  • Segue (show type)

    self.performSegueWithIdentifier("toVC2segue", sender: self) 
  • create program files:

     // prepare for future display let storyboard = UIStoryboard(name: "Main", bundle: nil) let navigationVC = UIApplication.sharedApplication().keyWindow?.rootViewController as! UINavigationController // prepare next view let vc = storyboard.instantiateViewControllerWithIdentifier("VC2id") self.tabBarController?.navigationController?.pushViewController(vc, animated: true) 

but both of them cause the tab bar to disappear.

I also tried

 self.hidesBottomBarWhenPushed = false 

but that didn’t change anything.

Do you have another idea?

PS: I updated my diagram above ...

Edit: after reading the answers below, I tried to add another navigation controller:

-> NavigationController β†’ LoginView β†’ TabBarController β†’ NavigationController β†’ VC1 β†’ VC2

but now I have two navigation bars superimposed on VC1 and VC2 ...

+5
source share
4 answers

You need to install TabBarContoller as rootViewController application. Thus, the circuit should be as follows:

TabBarContoller -> Tab1 -> UINavigationController -> ViewContoller1 -> ViewContoller2.

In this case, you can move between ViewContoller1 and ViewContoller2, and the TabBarContoller will remain visible.

+6
source

Your view hierarchy should not look like this if you want to keep the tabBar.

-> NavigationController β†’ TabBarController β†’ VC1 β†’ VC2

You should change it to β†’ TabBarController β†’ NavigationController β†’ VC1 β†’ VC2

+5
source

First, you need to make sure your VC1-VC2 segue is of type (Show eg Push) . Then you need to make sure that VC1 is built into the UINavigationController enter image description here

0
source

NavigationController-> TabBarController β†’ NavigationController-> First View-> Tapped Button-> FirstDetailsViewController.storyboard (the NavigationController check is a built-in view controller)

enter image description here

0
source

Source: https://habr.com/ru/post/1242484/


All Articles