iPhone Dev:激活 tabBar 按钮的视图

发布于 2024-07-30 10:43:42 字数 340 浏览 1 评论 0原文

我有一个应用程序,它有一个处理所有视图的 tabBar。 在第一个视图中,我有一个登录过程。 当该过程完成时,我想自动转到第二个 tabBar 视图,而不让用户单击其各自的 tabBar 按钮。

到目前为止,我所要做的就是用以下命令突出显示该按钮:

myTabBar.selectedItem = [myTabBar.items objectAtIndex:1];

但我不知道如何自动将与该按钮相关的第二个视图放在前面。 到目前为止,用户必须在按钮亮起(选中)时按下按钮。

知道如何做到这一点吗? 是否可以? 我们将不胜感激。 谢谢。

I have an application that has a tabBar that handles all the views. In the first view I have a login process. When that process finishes I want to go automatically to the second tabBar view without making the user to click in its respective tabBar button.

All I've got until now is to highlight the button with this:

myTabBar.selectedItem = [myTabBar.items objectAtIndex:1];

But I have no idea about how to bring the second view related to that button to the front, automatically. Until now the user has to press the button when it gets lighted (selected).

Any idea about how to do this? Is it possible? It would be much appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡水深流 2024-08-06 10:43:42

使用 selectedViewControllerselectedIndex 相应 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 方法应该可以正常工作。

Use the selectedViewController or selectedIndex methods of the corresponding UITabBarController.

In response to the comments on this answer, I have provided an example of how this might be accomplished:

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];

In my testing, it seems that using the selectedViewController method of UITabBarController to set the current view does not update the selectedIndex property (the new view is displayed but the selected UITabBarItem is not changed). This is in contrast to the behavior promised in the documentation. Using the selectedIndex method as demonstrated in the code snippet above should work fine, however.

-残月青衣踏尘吟 2024-08-06 10:43:42

您应该实现 UITabBarControllerDelegate 协议,如下所述: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html

要更改活动选项卡,请使用 tabBarController:shouldSelectViewController:
正如文档“您可以使用此方法动态决定是否应将给定选项卡设为活动选项卡”中所述。

you should implement the UITabBarControllerDelegate protocol, as explained here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html

to change the active tab, use tabBarController:shouldSelectViewController:
As explained in the documentation "You can use this method to dynamically decide whether a given tab should be made the active tab."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文