2
votes

I have a problem, I have 2 view controllers on the tab bar controllers. Both these controllers are showing tabs. But when I made a push segue from View controller 1 to View controller 3. View controller 3 do not show the tab bar.

I want to show tab on all the controllers of my application. my situation

4
Just shift the position on navigation controller before controller 1. it will work as you are excepting. - Pawan Rai

4 Answers

8
votes

Change your Storyboard Design:

  • set TabBar View Controller as initial ViewController

  • set your UINavigationViewController as root view controller for each Tab

  • After all, your Design structure will look like mention Image

enter image description here

1
votes

Your problem exist because your UITabViewController is embedded in the navigation stack that you initialize as a initial controller.

You must re-build things so that your tab bar controller tabs opens to a new navigation stack.

  • Remove the first UINavigationController , you don't need it ( if you want it don't use a push segue, use a modal segue, and you won't then be referring back to that UINavigationController's viewController stack from inside your UITabViewController
  • Embed each of the first UIViewControllers in your UITabViewController inside a separate UINavigationController.

Now you can push segue within your UITabViewController's tabs

0
votes

You should realize your struct of views.

Now, you have a NavigationController first, and its rootViewController is a Tab BarController.

NavigationController[0] = TabBarController

and your TabBarController has 2 ViewController( Controller 1 and Controller 2 )

NavigationController[0] = TabBarController

then it includes 2 controllers like

TabBarController[0] = Controller 1

TabBarController[1] = Controller 2

when you call

self.navigationController.pushViewController

it means the NavigationController push to Controller 3, so controller 3 will not show tab bar because it is not in TabBarController.

if you wanna push to controller 3 and still has tab bar, you can insert a container in Controller 1 ( or insert a View ), and create a NavigationController like this

let nav = NavigationController(rootViewController: yourController1)
self.yourViewInsertedInController1.addSubview(nav.view)

then in yourController1 run

self.navigationController.pushViewController

it will be right.

-1
votes

To add the view controller to the tab bar controller's array of view controllers, drag from the tab bar controller to that view controller, holding down the Control key. Select Relationship Segue > view controllers from the menu that appears.