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

问题描述

请告诉 presentViewController UiNavigationController 之间的区别?我可以使用 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 提供了一种显示所谓的模态视图控制器的机制;即

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之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 00:42