在带有导航控制器的选项卡栏应用程序中,如何从选项卡栏层次结构中的第一个视图开始
我有基于选项卡栏的应用程序,我想在每次按下选项卡时启动与它们关联的第一个视图。问题是,当应用程序启动时,它从第一个视图开始,但在使用应用程序时,我可能会深入导航到一个选项卡,现在如果我想使用与按下的选项卡关联的主视图再次启动它,该怎么办?
I have tabbar based application, I want to start each time tab is pressed to start with first view they are associated with. Problem is it starts with first view when its a start of application but while using application i may navigate deep in to one tab and now what to do if i want to start it again with main view associated with that tab which is pressed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用选项卡栏委托来覆盖此行为。
UITabBarControllerDelegate
记录如下:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
您需要查看:
tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
每次触发此委托方法时,您都可以触发相应导航控制器的
popToRootViewController:animated
方法。通常,您的应用程序委托也可以是选项卡控制器委托,但这取决于您的实现。You can use the tabbar delegates to override this behaviour. The
UITabBarControllerDelegate
is documented here:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
You would want to look at:
tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
Everytime this delegate method is triggered you can trigger the corresponding navigation controller's
popToRootViewController:animated
method. Normally you'd have your app delegate be the tabbar controller delegate also, but that's up to your implementation.