2013-09-26 33 views
3

我有UITabBarController并推动两个视图。我希望第一个视图成为默认值,并且按钮在加载时处于“选定”状态。的UITabBarController所选项目

我的问题是tabBarItem没有选择的背景时,它加载。我必须点击它才能显示选中的内容。我也为标签栏项目使用自定义图像,并在每个视图中配置它们,并将其添加到tabBarController中。

我使用这个设置选择的项目:

_tabBarController.selectedViewController = [_tabBarController.viewControllers objectAtIndex:0]; 

的UITabBarItem获取我添加到tabBarController每个视图中创建:

-(UITabBarItem *)tabBarItem 
{ 
    return [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"tab_select_indicator_map.png"] tag:0]; 
} 

我怎么也有tabBarItem显示选择的状态?

+0

你有没有找到一个解决问题了吗?我推送一个tabbarcontroller并且最初的选项卡图标未被选中(尽管视图控制器正确显示)。只在实际的选项卡图标上点击才能选中它。我以编程方式设置'selectedIndex'。 –

回答

1

使用下面显示的代码选择tabBarItem当你的TabBar被加载。

[_tabBarController setSelectedIndex:0]; // your can set index as per your requirement. 

Eited:

确保您创建tabBarItem诸如此类

UITabBarItem* myTestingItem = [[UITabBarItem alloc] init]; 
[myTestingItem setFinishedSelectedImage: [UIImage imageNamed: @"btnTabItem-SelectedImage.png"] 
       withFinishedUnselectedImage: [UIImage imageNamed: @"btnTabItem.png"]]; 
+0

但它不会给tabBarItem“选择”状态。我仍然需要点击才能显示该状态。 –

+0

@SteveSloka - 请检查我编辑的答案:) – iPatel

+0

我更新了问题以显示如何创建tabBarItem。现在我没有设置未选择的图像,但是当我点击时,我会得到一个。 –