0

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.

Saad Qureshi
  • 728
  • 2
  • 7
  • 21
  • Are you talking about a slide out controller? Check this out https://github.com/KyleGoddard/KGFloatingDrawer – AMAN77 Dec 23 '16 at 09:45
  • I'm assuming that you meant when you tap on "List", it shows the List ViewController, and the "List" tab then changes to "Map", and vice versa. But that doesn't seem like a good design and is counter productive to what a tab bar is supposed to do. Is there any reason why they can't be two separate tabs? – Chan Jing Hong Dec 23 '16 at 09:52
  • @AMAN77 Not really. – Saad Qureshi Dec 23 '16 at 09:58
  • Then you probably just want a splitViewcontroller – AMAN77 Dec 23 '16 at 09:59
  • Chan, you understood the problem perfectly and that is the requirement of the designer. – Saad Qureshi Dec 23 '16 at 09:59
  • Read Chan's comment. He explained it perfectly. – Saad Qureshi Dec 23 '16 at 10:09
  • 1
    @Saad i have got your problem. I have already provided you a solution in below answer. If you want to do it like in that manner i could explain further. – Dheeraj D Dec 23 '16 at 10:28

1 Answers1

0

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 { } } }

Dheeraj D
  • 4,386
  • 4
  • 20
  • 34
  • Why does the `UITabBarController` need to be made a subclass of `ContainerView `? Wouldn't this make multiple TabBarControllers? Why not make the internal 2 activities a subclass of `ContainerView ` and link that to `UITabBarController`? – Saad Qureshi Dec 23 '16 at 11:08
  • 1
    No.. You have to Subclass 'UITabBarController' to identify the the index selection of your tab bar. Create ThirdVC as a first controller for your first Tab and Add ContainerView To your ThirstVC and in that Container View you will switch between two i.e FirstVC and SecondVC. And on same Tabbarcontroller you will be able to change the Tab icon. – Dheeraj D Dec 23 '16 at 11:10