我第一次能够在tabbar Controller上设置badgeValue但是在注销后我无法设置tabbar badgeValue,它总是返回nil。
let tabArray = self.navigationController?.tabBarController?.tabBar.items as NSArray!
if(tabArray != nil)
{
let tabItem = tabArray.objectAtIndex(3) as! UITabBarItem
tabItem.badgeValue = "100";
}else
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let main_tabbar = storyboard.instantiateViewControllerWithIdentifier("tabbar") as! tabbar
let tabArray = main_tabbar.tabBar.items as NSArray!
if(tabArray != nil)
{
//...........Problem is Here ......
let tabItem = tabArray.objectAtIndex(3) as! UITabBarItem
tabItem.badgeValue = "100"; //Here is not Update but code working
}else
{
print("Not gatting tabbar")
}
}
在故事板上我创建了TabbarController,并设置标识名称为“tabbar”,类名为tabbar。
这是我的代码在“退出”按钮上我显示第一页:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewControllerWithIdentifier("FirstNavigation")
UIApplication.sharedApplication().delegate?.window??.rootViewController = initialViewController
UIApplication.sharedApplication().delegate?.window??.makeKeyAndVisible()