我正在尝试检索为指定选项卡显示的值。它以前工作过,但由于某种原因停止了?下面int current_badge =
的代码行是获取徽章值的地方,无论徽章值实际是什么,它都会返回零。我在一个脱离 uitabcontroller 的 viewcontroller 中。有人对我做错了什么有任何想法吗?
更新: 这似乎是因为我在标签控制器之外的视图控制器中。将相同的代码移动到选项卡视图控制器中,它工作正常。有没有更好的方法来确定 tabcontroller 中的徽章值?
-(void)badgeUpdate:(int)tab:(int)dayspan
{
// getting the current badge amount
int current_badge = [[[super.tabBarController.viewControllers objectAtIndex:tab] tabBarItem].badgeValue intValue];
// testing for badge level
if (current_badge > 0)
{
// testing for updates on tab for dayspan or longer
int updates_waiting = [self updatesWaitingCheck:tab:dayspan];
if (updates_waiting > 0)
{
// setting new badge level on tab
[[[[[self tabBarController] viewControllers] objectAtIndex:tab] tabBarItem] setBadgeValue:[NSString stringWithFormat:@"%d", updates_waiting]];
}
else
{
// turning off badge display
[[[[[self tabBarController] viewControllers] objectAtIndex:tab] tabBarItem] setBadgeValue:nil];
}
}
}