Tab Bar mysteriously disappears?

1.8k Views Asked by At

Attached are two images. The first shows my current main.storyboard, and the second shows my problem when I run the app. I have a tab bar controller that has two tabs. On the first tab there is a button. When pressed, the button goes to another view controller with content. At the top is a Navigation bar with a back button. After viewing content, I press the back button, and am back on the original page with the button, but the tab bar is missing. I have seen a few answered questions, but it appears they made their tab bar in the view controller instead of the storyboard. Another says that I should never return to a previous view unless I use an unwind segue. Is this true? If so, how do I set up an unwind segue. If not, how do I fix this problem otherwise? Thank you. https://i.stack.imgur.com/IYmX2.png https://i.stack.imgur.com/7slt5.png

2

There are 2 best solutions below

5
On

The problem is in the wiring of your ViewControllers. You have probably embedded your UITabBarController inside the UINavigationController and not the other way around.

A correct layout looks like this in Interface Builder :

Layout in Interface Builder

To reproduce:

  • In Interface Builder drop a UITabBarController. This will come with 2 UIViewController's already wired in.
  • Pick one of the UIViewController's (let's call it VController1) and click on Editor / Embed in / Navigation Controller. This wires the VController1 to live inside a UINavigationController that is inside the UITabBarController
  • Add a 3rd UIViewController next to VController1 Let's call it VController3
  • Wire in a segue between VController1 and VController3, for example with a button.

I hope that's clear enough

0
On

Try Linking the button in your viewcontroller (other than the views of the tabbed bar controller) with the tabbed bar controller. Create a segue that links the button with the controller of the tabbed bar application