     }
 
     func updateVisibleViewController() {
-        if visibleViewController != selectedViewController {
+        tabBar.selectedItem = selectedViewController.tabBarItem
+        if visibleViewController.parentViewController != self {
+            showViewController(childViewControllers[selectedTab.rawValue] as! UIViewController)
+        }
+        else if visibleViewController != selectedViewController {
             transitionControllers(visibleViewController, selectedViewController)
         }
     }

        }
        didSet {
            updateVisibleViewController()
            tabBar.selectedItem = selectedViewController.tabBarItem
        }
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(tabBar)
        tabBar.delegate = self
        modalTransitionStyle = .CrossDissolve

        updateTabBarItems()
        updateVisibleViewController()
    }

    override func viewDidLayoutSubviews() {
