您想从当前选项卡中移除一个徽章,还是要移除该徽章?
这样做的正确的地方,无论哪种方式,是在你的标签栏控制器的委托,于:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
注意,只要用户点击标签栏按钮,无论这个函数被调用显示的新视图控制器与旧视图控制器不同,因此您需要跟踪当前可见视图控制器。在这里,你会更新,也:
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController {
if(viewController != self.currentTabVC) {
// if you want to remove the badge from the current tab
self.currentTabVC.tabBarItem.badgeValue = nil;
// or from the new tab
viewController.tabBarItem.badgeValue = nil;
// update our tab-tracking
self.currentTabVC = viewController;
}
}
可能重复http://stackoverflow.com/questions/2476903/remove-bagde-from-tabbar-item – jer 2010-08-10 00:03:42