문제

Any idea why this works:

[[[[[self tabBarController] tabBar] items] objectAtIndex:2] 
                                          setBadgeValue:@"Hello"];

But this doesn't?

[[self tabBarItem] setBadgeValue:@"Hello"];

I would rather not have to provide an explicit tab bar index (2 in the code above). Also, is there a way to get the tab bar index from within the view controller in the case where the first snippet is the only way to make this work?

Thanks.

도움이 되었습니까?

해결책

Is the tabBarItem you refer to there actually an item in the tabBarViewController? If its not then theres your problem. You can know the index of your viewController because u specifiy the order when you set the view controllers in your tabBarviewCOntroller, so if you set viewController a first in your tabBarViewController then its button will have an index of 0.

With your comment your question become more clear to me, as the reply stated, perhaps once you set the UITabBarController viewController, it grabs its tabBarItem and later changes to that viewController property dont get updated by the tabBarViewController (i might be wrong this is a guess)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top