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

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

问题描述

我不知道何时应该使用导航控制器而不是将segue与普通的View Controller一起使用?
如果使用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?

你能举个例子吗?

推荐答案

简答:使用带有showsegue的导航控制器仅实现DRILL DOWN行为。

例如,
Navigation Controller→作者→书籍和rarr;预订

For example, Navigation Controller → Authors → Books → Book


  • 对于root(作者)下方的每个级别,导航控制器自动添加标题栏和后退按钮。所以在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的FoodTracker教程的奇怪布局开始开发iOS应用程序(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 Storyboard


  • 第一个导航控制器使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).

但是,膳食细节用于显示现有膳食和添加新膳食。要添加新餐,需要取消和保存按钮。第二个导航控制器允许通过将膳食细节设为根来添加这些按钮(参见上面的第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.

显示现有膳食是推送信号,但是添加一餐就是一种模式(一顿新餐不是深思熟虑的)。这很重要:不能仅仅按下Add Meal的原因是自动后退按钮(< My Meals)变得模棱两可:是保存还是取消?

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天全站免登陆