应用程序中有 UITabBar 和 UINavigationController 吗?
大家好,我是 iPhone 开发新手,我不理解整个 UINavigationController 和 UITabBarController 的想法。其中一种可以替代另一种 - Tweetie 等应用程序如何将两者结合起来?
我想让我的应用程序在底部有一个持久的选项卡栏(这似乎有效),而且在顶部也有一个导航栏,可以将视图推送/弹出到屏幕上,而无需删除选项卡栏。
- 我怎样才能做到这一点?
- 对于所有这些控制器,就我的 MainWindow.xib 而言,IB 中的层次结构应该是什么样子?
- 这里的最佳实践是什么?
非常感谢,
Hey everyone, I am new to iPhone development and I'm not understanding the whole UINavigationController and UITabBarController idea. Is one a substitute for the other - how do apps such as Tweetie combine both?
I'd like to have my app have a persistent Tab Bar @ the bottom (which seems to be working), but also a Navigation bar at the top which can push/pop views onto the screen without removing the tab bar.
- How can I accomplish this?
- What should the hierarchy look like in IB as far as my MainWindow.xib with regards to all of these controllers?
- What is best practice here?
Thanks very much,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将视图控制器包装在
UINavigationController
内,并将UINavigationController
放置在UITabBar
内。这对你来说效果很好......
示例:
Just wrap the view controller inside the
UINavigationController
and Place theUINavigationController
inside theUITabBar
.This will work fine for you…
Example:
使用选项卡栏应用程序的向导,并正常设置它。在要添加导航控制器的任何选项卡中,使用该库在 XIB 中创建它。我的 XIB 有:
请注意,视图中没有任何内容。请参阅下面的 viewDidLoad 了解 UINavigationController 附加到 UIView 的位置。
在选项卡的 ViewController 的头文件中(我在这里称之为 DescriptiveNameNavViewController ——对此没有特定的标准,但我使用 [Something]NavViewController 来提醒我这个 ViewController 包含一个带有导航堆栈的导航控制器。这是我在向导生成的 MainWindow.xib 中设置的控制器名称)设置一个 UINavigationController * IBOutlet,它附加了 XIB 中的导航控制器:
在 DescriptiveNameNavViewController 的控制器中,执行如下操作
: DescriptiveNameNavViewController 中的 delegate 非常重要,因为否则您将无法在 DescriptiveNameViewController 实例中调用您期望的方法以及推送到导航控制器堆栈中的任何其他内容。
在 DescriptiveNameNavViewController 中,实现如下所示的 UINavigationControllerDelegate 方法:
这将导致消息像您期望的那样传播到 UINavigationController 内的控制器。人们遇到的许多问题似乎都是因为 viewDidAppear: 或其他方法没有在推送到 NavigationController 的 ViewController 上被调用。
无论如何,请告诉我更多细节是否有帮助。
Use the wizard for a Tab Bar Application, and set it up as normal. In any tab where you want to add a navigation controller, create it in the XIB using the library. My XIB has:
Note that there isn't anything in the view. See viewDidLoad below for where the UINavigationController gets attached to the UIView.
In the header file for the Tab's ViewController (which I've here called DescriptiveNameNavViewController -- there isn't a particular standard for this, but I use [Something]NavViewController to remind me that this ViewController contains a navigation controller with the navigation stack. This is the controller name that I set in the MainWindow.xib that the wizard generates) Set up a UINavigationController * IBOutlet that has the navigation controller in the XIB attached to it:
In the controller for the DescriptiveNameNavViewController , do something like this:
Setting the delegate in the DescriptiveNameNavViewController is super-important, because otherwise you won't get the methods called that you expect in DescriptiveNameViewController instances and anything else you push into the navigation controller's stack.
In DescriptiveNameNavViewController, implement the UINavigationControllerDelegate methods like this:
And that will cause messages to get propagated to controllers inside the UINavigationController like you expect. It seems like many problems that people encounter are because the viewDidAppear: or other methods aren't getting called on the ViewControllers pushed into the NavigationController.
Anyway, let me know if more detail would help.