Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pan17

macrumors newbie
Original poster
Jul 9, 2012
11
0
I've tried this way in a TableViewController inside a TabBarController :

Code:
self.tabBarItem.badgeValue = @"AB";

Then the tab bar item badge didn't change when i run the code.

When i use this code:

Code:
[[[[self tabBarController] tabBar] items] objectAtIndex:0] setBadgeValue:@"AB"];

Then it works, why?

You have to change its badge value by accessing the tarBar items array?
 
Last edited by a moderator:
Are you sure self.tabBarItem matches [[[self tabBarController] tabBar] items] objectAtIndex:0]?

Yeah, cause i call self.tabBaritem inside the tableViewController which is the first tab of the TabBarController. At least i think it should be,right?
 
Why guess? Verify it.

Ok, i tried this:
Code:
if ([[[[[self tabBarController] tabBar] items] objectAtIndex:0] isEqual:self.tabBarItem]) {
            NSLog(@"Hello");
        }
        NSLog(@"%@",[[[[self tabBarController] tabBar] items] objectAtIndex:0]);
        NSLog(@"%@",self.tabBarItem);

Then got these output:
Code:
2012-07-13 10:01:49.532 Flicker[2725:f803] <UITabBarItem: 0x6a53310>
2012-07-13 10:01:49.533 Flicker[2725:f803] <UITabBarItem: 0x6c708e0>

So, they are not the same. But why?
 
How (and where) is self.tabBarItem assigned?

Ah, i kinda get it.
So, the self is a UITableViewController, so self.tabBarItem is not the same as [[[self tabBarController] tabBar] items] objectAtIndex:0]. So, in this case, i have to get the tabBarController first then get the tabBar items then get the corresponding tabBarItem it has,right?
What i thought is:self.tabBarItem should be the tabBarItem inside that UITableViewController, but it turns out incorrect. But what is the self.tabBarItem??
Thanks
 
Did you check the documentation?

Yeah, the doc says this which i don't understand much.
tabBarItem
The tab bar item that represents the view controller when added to a tab bar controller.

@property(nonatomic, retain) UITabBarItem *tabBarItem
Discussion
This is a unique instance of UITabBarItem created to represent the view controller when it is a child of a tab bar controller.
The first time the property is accessed, the UITabBarItem is created.
Therefore, you shouldn’t access this property if you are not using a tab bar controller to display the view controller.
To ensure the tab bar item is configured, you can either override this property and add code to create the bar button items when first accessed or create the items in your view controller’s initialization code.

The default value is a tab bar item that displays the view controller’s title.
 
Last edited by a moderator:
This property sounds like what you want then. Hmm...

And I find it curious that your self.tabBarItem was non-nil (which I was expecting to be; nil, that is). Have you tried checking it against all the tabBar items? I'm wondering if it matches one of the other tabs.
 
This property sounds like what you want then. Hmm...

And I find it curious that your self.tabBarItem was non-nil (which I was expecting to be; nil, that is). Have you tried checking it against all the tabBar items? I'm wondering if it matches one of the other tabs.

nah, I didn't. Thank you,though.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.