UITabBarController最初突出显示所有标签栏项目图像

时间:2014-05-26 01:34:07

标签: ios uitabbarcontroller

我以编程方式实例化将管理2个视图控制器的UITabBarController,然后将其设置为rootViewController。但是,当视图出现时,它会突出显示所有标签项的图像(尽管文本已正确突出显示)。无论我设置为selectedIndex,图像都会突出显示。只有当您点击标签栏项目时,它才会实际切换图像上突出显示的状态。这里发生了什么?

代码:

UITabBarController *tabController = [[UITabBarController alloc] init];
UIStoryboard *storyboard = [self storyboard];
OGVideoStreamViewController *questionsController = [storyboard instantiateViewControllerWithIdentifier:@"OGVideoStreamViewController"];
questionsController.isQuestion = YES;
OGVideoStreamViewController *answersController = [storyboard instantiateViewControllerWithIdentifier:@"OGVideoStreamViewController"];
answersController.isQuestion = NO;
OGMatchesViewController *matchesController = [[OGMatchesViewController alloc] initWithNibName:@"OGMatchesViewController" bundle:nil];

questionsController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Questions" image:[UIImage imageNamed:@"Tab Icon - Questions"] tag:0];
answersController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Answers" image:[UIImage imageNamed:@"Tab Icon - Answers"] tag:1];
matchesController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Inbox" image:[UIImage imageNamed:@"Tab Icon - Inbox"] tag:2];

[tabController setViewControllers:@[questionsController, answersController, matchesController] animated:NO];
tabController.selectedViewController = questionsController;


[[UIApplication sharedApplication] keyWindow].rootViewController = tabController;

enter image description here

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,这是由于我打电话:

[UIView appearance].tintColor = [UIColor colorWithRed:1.000
                        green:0.793
                         blue:0.236
                        alpha:1.000];

我在AppDelegate中调用它,所以我可以将其更改为以下内容:

self.window.tintColor = [UIColor colorWithRed:1.000
                    green:0.793
                     blue:0.236
                    alpha:1.000];