presentViewController 和 UINavigationController 之间的区别? [英] difference between presentViewController and UINavigationController?

查看:38
本文介绍了presentViewController 和 UINavigationController 之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请说出presentViewControllerUiNavigationController 的区别?我可以使用 presentViewController 而不是 UINavigationController 来导航应用程序中的不同视图吗?使用的场景是什么?

Please tell the difference between presentViewController and UiNavigationController? Could I use presentViewController instead of UINavigationController to navigate different views in the app? Whats the scenario to use either?

推荐答案

presentViewController 提供了一种机制来显示所谓的模态视图控制器;即,一个视图控制器,通过叠加在呈现控制器的顶部来完全控制您的 UI.

presentViewController offers a mechanism to display a so-called modal view controller; i.e., a view controller that will take full control of your UI by being superimposed on top of a presenting controller.

UINavigationController 提供了一种更灵活的机制,您可以在其中推送一个新控制器,然后弹出它,以便以有序的方式返回到前一个控制器.想象一下,导航控制器中的控制器只会从左到右构建一个序列.

UINavigationController offers a much more flexible mechanism where you can push a new controller, and later pop it, so to go back to the previous one, in a ordered way. Imagine that controllers in a navigation controller will just build a sequence from left to right.

我认为 presentViewController 最适合一次只显示一个 一个 视图控制器.你当然可以用它来堆叠更多的视图控制器(从而有点模仿"穷人的导航控制器),但我敢打赌,你很快就会发现一些东西无法按预期工作.

I think that presentViewController is most suitable for use with just one view controller being presented at a time. You can surely use it to stack more view controllers one on top of the other (and thus sort of "mimic" a poor-man's navigation controller), but my bet is you will quickly find something not working as you expected.

具体来说,这种限制的一个例子如下:当你关闭一个模态视图控制器(为了关闭"它),你所有的模态呈现的视图控制器(来自同一个呈现控制器)也将在一次.因此,您根本无法实现返回"/导航之类的功能.

Specifically, an example of such limitation is the following: when you dismiss a modal view controller (in order to "close" it), all of your modally presented view controllers (from the same presenting controller) will also be dismissed at once. So you simply will not be able to implement a "go back"/navigation like functionality.

所以,这取决于你想做什么.

So, it depends on what you are trying to do.

这篇关于presentViewController 和 UINavigationController 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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