我的 tabBar 项目似乎有问题。创建 tabBar 我可以设置我想要的 tabBarItem 的这个属性,如下所示:
viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
UIViewController *viewController4 = [[FourthViewController alloc]initWithNibName:@"FourthViewController" bundle:nil];
//Create our NavigationViewController object
NavigationViewController *navController = [[NavigationViewController alloc] initWithNibName:@"NavigationViewController" bundle:nil];
//Create our UINavigationController
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:navController];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[nav, viewController2, viewController4, viewController3];
nav.tabBarItem = [[UITabBarItem alloc]
initWithTitle:(@"Menukort")
image:[UIImage imageNamed:@"162-receipt.png"]
tag:0];
viewController2.tabBarItem = [[UITabBarItem alloc]
initWithTitle:(@"Favoritter")
image:[UIImage imageNamed:@"28-star.png"]
tag:1];
viewController3.tabBarItem = [[UITabBarItem alloc]
initWithTitle:(@"Info")
image:[UIImage imageNamed:@"104-index-cards.png"]
tag:2];
viewController4.tabBarItem = [[UITabBarItem alloc]
initWithTitle:(@"Kort")
image:[UIImage imageNamed:@"103-map.png"]
tag:3];
viewController2.tabBarItem.badgeValue = @"1";
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
所有这些代码都在一个单例中,因此共享对象应该不是问题。现在 - 我将如何在另一个类中设置这个 tabBarItem 的 badgeValue?
提前致谢。