0
votes

When a user clicks on a button, I create a UITabBarController with two viewcontrollers attached to it. I then push the TabBarController onto my navigationController stack and it displays without problems. The problem is trying to set a badge on one of the tab bar items when the tabbarControlelr is loaded, I tried:

[[self.tabBarController.viewControllers objectAtIndex:1] setBadgeValue:@"1"];

and a whole lot of variations of this one, but none gives me a round red button thingy on the tabbar item.

Any suggestions?

Thanks,

Ron

EDIT

Code how I present the tabBarController

Airline_RosterAppDelegate *appDelegate = (Airline_RosterAppDelegate *)[[UIApplication sharedApplication] delegate];
CrewHere *vc = [[CrewHere alloc] initWithNibName:@"CrewHere" bundle:nil];
vc.title = @"Crewlist";

MessagesDetailed *mvc = [[MessagesDetailed alloc] initWithNibName:@"MessagesDetailed" bundle:nil];
mvc.title = @"Messageboard";

[tabbar setViewControllers:[NSArray arrayWithObjects:vc, mvc, nil]];
[tabbar setToolbarItems:[NSArray arrayWithObjects:@"Crewlist", @"Messageboard", nil]];

[appDelegate.navigationController pushViewController:tabbar animated:YES];
1

1 Answers

0
votes

The property 'badgeValue' is defined on a UITabBarItem. You would set it with:

  UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: 1];
  item.badgeValue = @"1";
  ...

The above won't work, nor will your code, when 'the UITabBarController is loaded.' You can only do it after the controller appears because only at that point can you be sure that all the view elements actually exist. Put it in viewDidAppear:animated: for the tabBarController

[Edit, after your Edit]

You can't call setToolbarItems: with an NSArray of NSString; the array needs UITabBarItem. Instantiate with - (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag

Also, it appears that you are mixing tool bar and tab bar - they are different.