我想在选择TabBar中的某个项目时推送ViewController,我已编写以下代码,但是它不起作用
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
}
如何在选择选项卡项而不是切换到ViewController时推动ViewController
答案 0 :(得分:1)
替换
self.selectedViewController?.navigationController?.pushViewController(tabVC, animated: true)
使用
(self.selectedViewController as! UINavigationController ).pushViewController(tabVC, animated: true)