Combine 2 ViewControllers in a single tab of TabBarView and allow back and forth switching within the same tab

336 views Asked by At

So I want to do something like this in Xcode (using Swift):

enter image description here

enter image description here

There should be a TabBar VC that contains 2 VCs under a single tab. But when one of the tabs is opened, it should show the second VC icon and allow me to switch back and forth among the 2 VCs using the same button.

Like, when you tap on "List", it shows the List ViewController, and the "List" tab then changes to "Map", and vice versa.

EDIT: Incorporated the explanation made by Chan.

1

There are 1 answers

2
Dheeraj D On

You can do this using below Steps:

  1. Take a ContainerView for your Tabbar's first tab (That may be the ThirdVC).

  2. SubClass your UITabBarController.

  3. Manage one Global variable for current showing VC in app delegate or your gloal class.

  4. Perform check and update task here (In subclass of your tabbar controller)

    //Here you can write your logic to update the view controller for first tab. Get reference of FirstVC here or create a delegate from where you can update your first Tab.

    override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) { var selectedIndex = self.selectedIndex if selectedIndex == 0 { if currentVC == First { }else { } } }