如何在导航控制器之间切换?
情况:
我有一个基于“Navigation-Based-Application”模板的 Xcode 项目。所以这意味着我有一个管理 UIViewController 的单个 UINavigationController。
我想做什么:
我想要做的就是向我的项目中再添加一个 UINavigationController —— 并能够在它们之间来回切换。 (我想这样做是为了为一些单独的不相关内容腾出空间,这样它就没有后退按钮指向根视图控制器。)
问题:
如何在我的项目中再添加一个 UINavigationController 并在两个 UINavigationController 之间切换?
Situation:
I have an Xcode project based on the "Navigation-Based-Application" template. So that means I have a SINGLE UINavigationController that manages a UIViewController.
What I want To Do:
What I want to do is add one more UINavigationController to my project -- and be able to switch back and forth between them. (I want to do this to make space for some seperate unrelated content so that it does not have a back button pointing back to the root view controller.)
Question:
How do I add one more UINavigationController to my project and switch between the two UINavigationControllers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最常见、最自然的 iPhone 操作系统方法是将
UITabBarController
添加到您的应用程序中。 Xcode 模板标签栏应用程序将指导您正确使用它。但是...
如果您不喜欢在应用程序中使用选项卡栏,并且希望在不同的
UINavigationController
实例(或任何与此相关的UIViewController
)之间切换,你可以做这样的事情。首先,您需要在适当的位置创建
UINavigationController
实例(例如,一个新的视图控制器,或者如果您想采取简单的方法,则在您的应用程序委托中)。然后,您只需交换应该可见的导航控制器的视图即可在控制器之间切换。应用程序委托中的示例,“firstNavigationController”和“secondNavigationController”是 UINavigationController 实例变量:
这将仅显示第一个而不是第二个导航控制器。请注意,这个示例非常简单。我没有考虑到您应该正确处理
viewWillAppear:
、viewDidAppear:
等方法。The most common, and natural iPhone OS, way of doing this is to add a
UITabBarController
to your application. The Xcode template Tab Bar Application will guide you in the right direction on how to use it.But...
If you don't like to have a Tab Bar in your application, and wish to switch between different
UINavigationController
instances (or anyUIViewController
for that matter), you can do something like this.First you need to create your
UINavigationController
instances in a appropriate place (for example a new view controller, or in you Application Delegate, if you want to take the easy way out). You can then switch between controllers by just swapping which Navigation Controller's view that should be visible.Example in the Application Delegate, "firstNavigationController" and "secondNavigationController" are
UINavigationController
instance variables:This will simply display the first instead of the second Navigation Controller. Note that this example is very simple. I didn't take into consideration that you should correctly handle the methods
viewWillAppear:
,viewDidAppear:
and so on.