0

当用户单击按钮时,我创建了一个带有两个视图控制器的 UITabBarController。然后我将 TabBarController 推到我的 navigationController 堆栈上,它显示没有问题。问题是在加载 tabbarControlelr 时尝试在其中一个选项卡栏项目上设置徽章,我尝试过:

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

以及这个的很多变体,但没有一个在标签栏项目上给我一个圆形的红色按钮。

有什么建议么?

谢谢,

罗恩

编辑

编写我如何呈现 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];
4

1 回答 1

0

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.

于 2013-04-25T22:34:52.393 回答