在 Storyboard 中创建 TabBarControllerDelegate
我在 Storyboard 驱动的 iOS5 应用程序中创建 UITabBarControllerDelegate 时遇到困难。情况如下:
- 我有一个初始屏幕,最终将处理登录,但当前只有一个按钮,可将用户发送到...
- ...带有五个选项卡的选项卡栏控制器。每个选项卡都转到...
- ...根目录下有许多子视图控制器的导航控制器。
(如果有帮助,相关情节提要部分的屏幕截图位于此处。)
当用户切换时选项卡,我总是希望用户被定向到该特定导航控制器的根视图控制器,而不是最近访问的视图控制器(这是默认行为)。
我知道要做到这一点,我需要在按下选项卡时调用 popToRootViewControllerAnimated,如所讨论的 此处和这里,但我不知道如何在故事板中做到这一点。我怎样才能做到这一点而不废弃故事板并重新开始?
谢谢!
I'm having difficulty creating a UITabBarControllerDelegate in my Storyboard driven iOS5 application. Here is the situation:
- I have an initial screen that will eventually handle login but which currently just has a button that sends the user to...
- ...a Tab Bar Controller with five tabs. Each of these tabs go to...
- ...a Navigation Controller with many child View Controllers under the root.
(If it helps, a screenshot of the relevant Storyboard section is here.)
When the user switches tabs, I always want the user to be directed to the Root View Controller for that particular Navigation Controller, and not the most recently visited View Controller (which is the default behavior).
I understand that to do so, I need to call popToRootViewControllerAnimated when a Tab is pressed as discussed here and here, but I can't figure out how to do that within the storyboard. How can I do this without scrapping the storyboard and starting over?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题有不止一种解决方案(这是设计模式决策的问题)。其中一些可能是:
子类 UITabBarController 并将其设置为故事板中选项卡栏的自定义类(还将委托连接到您的对象以便进行处理)并覆盖 -tabBarController:didSelectViewController:< /strong> 委托方法
There are more than one solutions to your problem (its a matter of design pattern decision). Some of them could be:
Subclass UITabBarController and set it as the custom class of your tabbar in your storyboard (also connect the delegate to your object in order to be handled) and override the -tabBarController:didSelectViewController: delegate method
Pop to the root by calling -popToRootViewControllerAnimated from the viewWillDisappear event of every view that you want this behavior implemented
您可以创建自己的 TabBarController,实现实例化视图控制器的方法,
然后在 viewDidLoad 方法中使用视图控制器创建数组,在您的情况下,该数组将是您在 InterfaceBuilder 上设置的 NavigationController 的标识符。
You can create your own TabBarController, implement a method that instantiate your view controllers
Then in the viewDidLoad method you create the array with the view controllers, that in your case would be the NavigationController's identifier that you set on the InterfaceBuilder.