您想從當前選項卡中移除一個徽章,還是要移除該徽章?
這樣做的正確的地方,無論哪種方式,是在你的標籤欄控制器的委託,於:
- (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