I want to push a ViewController when an item in TabBar is selected I have written following code but it is not working
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let ind = tabBarController.viewControllers!.index(of:viewController) , bottomBarTabsArray[ind].viewType == BottomBarInfo.VIEWTYPE_ASSISTANT { //
let tabVC = AppStrings.appStoryBoard.instantiateViewController(withIdentifier: "assitantViewControllerID") as! AssitantViewController
self.selectedViewController?.navigationController?.pushViewController(tabVC, animated: true)
return false
}
return true
}
how to push ViewController when tabbar item is selected instead of switching to ViewController
Replace
self.selectedViewController?.navigationController?.pushViewController(tabVC, animated: true)
with
(self.selectedViewController as! UINavigationController ).pushViewController(tabVC, animated: true)