iPhone Dev:激活 tabBar 按钮的视图
我有一个应用程序,它有一个处理所有视图的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 selectedViewController 或 selectedIndex 相应 UITabBarController。
为了回应对此答案的评论,我提供了一个如何实现这一点的示例:
在我的测试中,似乎使用 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:
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.
您应该实现 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."
最后我在这里得到了解决方案:
iphone sdk:从第一个选项卡栏项目单击按钮时将焦点设置为不同的选项卡栏视图
无论如何,谢谢。
Finally I got the solution here:
iphone sdk: set focus to different tabbar view on button click from first tabbar item
Thanks anyways.