我有一个应用程序,它有一个处理所有视图的tabBar。在第一个视图中,我有一个登录过程。当该过程完成时,我想自动进入第二个tabBar视图,而不会让用户单击其各自的tabBar按钮。
到目前为止我所要做的就是用这个突出显示按钮:
myTabBar.selectedItem = [myTabBar.items objectAtIndex:1];
但我不知道如何自动将与该按钮相关的第二个视图放到前面。到目前为止,用户必须在点亮(选中)时按下按钮。
关于如何做到这一点的任何想法?可能吗?非常感谢。感谢。
答案 0 :(得分:1)
使用相应selectedViewController的selectedIndex或UITabBarController方法。
在回答对这个答案的评论时,我提供了一个如何实现这一点的例子:
id firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:[NSBundle mainBundle]];
id secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, nil];
[firstViewController release];
[secondViewController release];
// Select the second tab bar item and its view
self.tabBarController.selectedIndex = 1;
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
在我的测试中,似乎使用UITabBarController的selectedViewController方法来设置当前视图不会更新selectedIndex属性(显示新视图但不更改选定的UITabBarItem)。这与文档中承诺的行为形成对比。但是,使用上面代码片段中演示的selectedIndex方法可以正常工作。
答案 1 :(得分:1)
您应该实现UITabBarControllerDelegate协议,如下所述:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
要更改活动选项卡,请使用tabBarController:shouldSelectViewController: 如文档中所述“您可以使用此方法动态决定是否应将给定选项卡设置为活动选项卡。”
答案 2 :(得分:0)