Best way to update badgeValue of UITabBarController from a UIView

无人久伴 提交于 2019-11-28 08:33:18

Thanks to alku83 who pointed me in the right direction the code is:

[[super.tabBarController.viewControllers objectAtIndex:2] tabBarItem].badgeValue = @"1";

I'm using Xcode 4.5 with Storyboards and iOS 6, so the answer may have changed since it was originally posted.

First you have to access the Tab Bar Controller like this:

UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;

Then you can set the badge like so:

[[tabController.viewControllers objectAtIndex:1] tabBarItem].badgeValue = @"New!";

I don't have the code on hand right now, but it should be something more like

...otherViewController.tabBarItem.badgeValue = 1;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!