我什么时候应该使用导航控制器? [英] When I should use Navigation Controller?

查看:20
本文介绍了我什么时候应该使用导航控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么时候应该使用导航控制器而不是使用 segue 和普通视图控制器?如果使用segue,Modal和Push segue有什么不同?

I don't know when I should use Navigation Controller instead of use segue with normal View Controller? And if use segue, which different between Modal and Push segue?

你能举个例子吗?

推荐答案

简答:使用带有show"segues 的 Navigation Controller 仅用于实现 DRILL DOWN 行为.

例如,导航控制器 →作者 →书籍→预订

For example, Navigation Controller → Authors → Books → Book

  • 对于根"(作者)下的每个级别,导航控制器自动添加标题栏和后退按钮.所以在 Books 上,后退按钮会自动命名为<Authors".

  • For each level below the "root" (Authors), the Navigation Controller automatically adds the title bar and back button. So on Books, the back button is automatically named "<Authors".

子视图控制器必须与 SHOW segues 连接 -- show segues 告诉导航控制器这是父子关系"并导致预期的滑入-右转.(要跳出层次结构,例如 Books → Login,请改用模态 segue.)

The child View Controllers must be connected with SHOW segues -- show segues tell the Navigation Controller "this is a parent-child relationship" and cause the expected slide-in-from-the-right transition. (To jump outside the hierarchy, for example, Books → Login, use a modal segue instead.)

根视图控制器有一个导航栏,您可以向其中添加更多条形按钮,但子视图控制器没有,因为它是自动添加的.

The root View Controller has a navigation bar that you can add more bar buttons to, but child View Controllers don't, because it's added automatically.

现在 Apple 的 开始开发 iOS 中的 FoodTracker 教程的布局看起来很奇怪可以解释应用程序(Swift).**第二个嵌套导航控制器怎么了?它只是一个简单的餐食列表:点击餐食以在餐食详情中显示,或点击添加到餐食详情变成添加餐食.

Now the odd-seeming layout of the FoodTracker tutorial in Apple's Start Developing iOS Apps (Swift) can be explained. **What's up with that second nested Navigation Controller? It's just a simple list of meals: tap a meal to show it in Meal Detail, or tap Add to and Meal Detail becomes Add Meal.

FoodTracker 故事板

  • 第一个导航控制器使 My Meals 成为向下钻取层次结构的根,用于从那里推送"的任意数量的视图(无需进一步的导航控制器来执行此操作).

  • The first Navigation Controller makes My Meals the root of the drill-down hierarchy for any number of views "pushed" from there on (no further Navigation Controllers are needed just to do that).

但是,Meal Detail 用于显示现有餐点和添加新餐点.要添加新餐点,需要取消和保存按钮.第二个导航控制器允许通过将 Meal Detail 设为根来添加这些按钮(参见上面的第 3 点).

But, Meal Detail is used for both displaying an existing meal and adding a new meal. To add a new meal, Cancel and Save buttons are needed. The second Navigation Controller allows those buttons to be added (see 3rd point above) by making Meal Detail a root.

显示现有的餐点是一种推送转场,但添加餐点是一种模态转场(新餐点不是向下钻取).这很重要:不能只按添加餐食的原因是自动后退按钮(<我的餐食")变得不明确:它是保存还是取消?

Displaying an existing meal is a push segue, but adding a meal is a modal segue (a new meal isn't a drill-down). This is important: the reason Add Meal can't just be pushed is that the automatic back button ("< My Meals") becomes ambiguous: does it save or cancel?

因为导航"和推送"是非常笼统的术语,并且因为获得免费的后退按钮很好,所以很容易认为导航控制器可以从任何地方移动到任何地方,但该行为仅用于分层遍历.

Because "navigation" and "push" are very general terms, and because it's nice to get a free back button, it's tempting to think Navigation Controllers are to go from anywhere to anywhere, but the behavior is intended just for hierarchical traversal.

(这是一个老问题,但作为 iOS n00b 我也对此感到困惑,就像 OP 一样,我仍然有问题.)

(This is an old question but I was also confused about this as an iOS n00b and like the OP I still had questions.)

这篇关于我什么时候应该使用导航控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆