1

实际上,问题出在问题标题中。问题是我需要在我的应用程序中更改 UITabBarController 的活动选项卡。我通过以下方式做到这一点:

[self.tabBarController setSelectedIndex:2]; //2 is just for instance

奇怪的是它确实改变了选定的选项卡,但该选项卡的标题颜色仍然保持不变(灰色),我希望它变成白色,就像我点击选项卡一样。你有什么建议吗?

编辑:

这是设置标签栏初始状态的代码:

UITabBarController *mvc = [[UITabBarController alloc]init];

AccountManagmentViewController *accountvc = [[AccountManagmentViewController alloc]init];
ListTableViewController *ltvc = [[ListTableViewController alloc]init];
UINavigationController *listNavcon = [[UINavigationController alloc]initWithRootViewController:ltvc];


CalendarViewController *calendarvc = [[CalendarViewController alloc]init];
UINavigationController *calendarNavcon = [[UINavigationController alloc]initWithRootViewController:calendarvc];


ListsManagerViewController  *listsManager = [[ListsManagerViewController alloc]init];
UINavigationController *listsNavcon = [[UINavigationController alloc]initWithRootViewController:listsManager];

SettingsViewController *settings = [[SettingsViewController alloc]init];
UINavigationController *settingsNav = [[UINavigationController alloc]initWithRootViewController:settings];

[accountvc.tabBarItem setFinishedSelectedImage:[[EasyUITheme currentTheme]tabBarUserIconImageActive:YES] withFinishedUnselectedImage:[[EasyUITheme  currentTheme]tabBarUserIconImageActive:NO]];

[listsNavcon.tabBarItem setFinishedSelectedImage:[[EasyUITheme currentTheme]tabBarListsIconImageActive:YES] withFinishedUnselectedImage:[[EasyUITheme currentTheme]tabBarListsIconImageActive:NO]];
[calendarNavcon.tabBarItem setFinishedSelectedImage:[[EasyUITheme currentTheme]tabBarCalendarIconImageActive:YES] withFinishedUnselectedImage:[[EasyUITheme currentTheme]tabBarCalendarIconImageActive:NO]];
[listNavcon.tabBarItem setFinishedSelectedImage:[[EasyUITheme currentTheme]tabBarMain10IconImageActive:YES] withFinishedUnselectedImage:[[EasyUITheme currentTheme]tabBarMain10IconImageActive:NO]];
[settings.tabBarItem setFinishedSelectedImage:[[EasyUITheme currentTheme]tabBarSettingsIconImageActive:YES] withFinishedUnselectedImage:[[EasyUITheme currentTheme]tabBarSettingsIconImageActive:NO]];
[accountvc.tabBarItem setTitle:NSLocalizedString(@"Account", nil)];
[listsNavcon.tabBarItem setTitle:NSLocalizedString(@"Lists", nil)];
[calendarNavcon.tabBarItem setTitle:NSLocalizedString(@"Calendar", nil)];
[listNavcon.tabBarItem setTitle:NSLocalizedString(@"Words", nil)];
[settings.tabBarItem setTitle:NSLocalizedString(@"Settings", nil)];
4

2 回答 2

0
AccountManagmentViewController *accountvc = [AccountManagmentViewController instanceOfNibNamed:@"AccountManagmentViewController"];
UINavigationController *accountvcNavigationController = [[UINavigationController alloc] initWithRootViewController:accountvc];
accountvcNavigationController.navigationBarHidden = YES;
UITabBarItem* accountTabBarItem = [[UITabBarItem alloc] init];
[accountTabBarItem setTitle:@"Account"];
[accountTabBarItem  setFinishedSelectedImage: [UIImage imageNamed:@"tab3"]
                        withFinishedUnselectedImage: [UIImage imageNamed: @"tab3"]];
[accountvcNavigationController setTabBarItem: accountTabBarItem];
[viewControllers addObject:accountvcNavigationController];

像这样试试。它可能对你有用。

于 2013-05-10T13:01:27.263 回答
0

尝试实现一个UITabBarController委托。它有一个类似于didSelect: method提供的方法

UITabBar delegate:
tabBarController:didSelectViewController:

. 用户选择另一个选项卡后将调用它。

请参阅:UITabBarControllerDelegate协议参考

于 2013-05-15T05:05:30.097 回答