Katherine Jenkins Katherine Jenkins - 1 year ago 153
Swift Question

TabBar Item To Show RootController - Container-Embedded NavigationController TableViewController Stacks

I have the following storyboard:

enter image description here

If the user navigates to view A1-2, then selects Tab B, then selects Tab A ... they will be presented with TableViewController A1-2 (their recent "Tab A exit point").

I would like them to be presented with TableViewController A1 if they navigate to Tab B then decide to 'go back' and select Tab A; NOT where they navigated to previously (i.e. TableViewController A1-2, or their recent "Tab A exit point").

Basically, any tab selected (other than the one currently selected) will present the root view controller of that particular tab.

Is this possible with my storyboard setup?

Many, many thanks for any feedback.

Answer Source

You can have A1-2 and A1-1 dismissed upon tab-bar switch, and vise-versa if needed.

//set tab bar delegate and call this method
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
    if item == tabBarB {
        //dismiss viewController A1-2 and A1-1
        self.view.window!.viewControllerA1?.dismissViewControllerAnimated(false, completion: nil)
    } else {
        //dismiss miss viewController B1-2 and B1-1
        self.view.window!.viewControllerB1?.dismissViewControllerAnimated(false, completion: nil)

Let me know if this is what you were looking for.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download