UITabBar marking

Any idea why this works:

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

      

But isn't it?

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

      

I would rather not provide an explicit tab row pointer (2 in the code above). Also, is there a way to get the index of the tab bar from the view controller when the first snippet is the only way to do it?

Thank.

+2


source to share


1 answer


Is the tabBarItem a reference to the actual item in the tabBarViewController? If not, then your problem is. You can find out the index of your viewController because u sets the order when you set up view controllers in your tabBarviewCOntroller, so if you set the viewController first in your tabBarViewController then its button will have an index of 0.



With your comment, your question will become clearer to me, as the answer said, maybe after setting the UITabBarController viewController it grabs its tabBarItem and later changes to this property of the viewController will not update with the tabBarViewController (maybe I am wrong with this assumption)

0


source







All Articles