Question

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.

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top