我在" UITabBarController.selectedIndex"上遇到了崩溃。标签栏在执行的任何时候都没有变为零,这是令人惊讶的事实并且仍然在该特定行上出错。请引导我通过适当的解决方案。
let obj = self.storyboard?.instantiateViewControllerWithIdentifier("OfferViewController") as! OfferViewController
setFlagWhilePushingFromMenuViewController()
obj.screenName = SCREEN.MOBILE_RECHARGE.rawValue
rechargeManager.presentRechargeScreen = PRESENT_SCREEN.MOBILE.rawValue
if let tab : UITabBarController = self.revealViewController().frontViewController as? UITabBarController{
let index : Int = tab.selectedIndex // CRASH POINT
print("----->\(tab.selectedIndex)")
tab.selectedIndex = 1
let navig : UINavigationController = tab.viewControllers![index] as! UINavigationController
navig.pushViewController(obj, animated: true)
self.revealViewController().revealToggleAnimated(true)
}
else{
print("do something else")
}
答案 0 :(得分:0)
要获取tabar的selectedIndex,请应用以下代码
var application: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
var tabbarController = application.tabBarController as UITabBarController
var selectedIndex = tabBarController!.selectedIndex
你会得到像这样的selectedIndex。它在这里工作。