实际上,问题在于问题标题。问题是我需要在我的应用程序中更改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)];
答案 0 :(得分: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];
试试这样。它可能适合你。
答案 1 :(得分:0)
尝试实施UITabBarController
委托。它有一个类似于
didSelect: method
的方法
UITabBar delegate:
tabBarController:didSelectViewController:
。它将在用户选择另一个选项卡后调用。
请参阅:UITabBarControllerDelegate协议参考