iOS - PushViewController 与 PresentModalViewController 的区别

发布于 2024-12-13 23:18:44 字数 251 浏览 6 评论 0原文

当动画设置为“否”时,调用 presentModalViewControllerpushViewController 之间有什么区别

  • (即使是,那只是可以更改的动画样式)。
  • 在呈现模态视图时定义了导航控制器,因此它也可以通过调用堆栈进行导航,...

这只是为了能够从第一个推送的视图返回吗?呜啊啊啊……

我想差异在其他地方而且更深。不 ?

What is the difference beetween calling presentModalViewController and pushViewController, when :

  • animation is set to NO (even if yes, that's just an animation style that can be changed).
  • a navigation controller is defined when presenting the modal view, so it can be navigable too, with a call stack, ....

Is this just to be able to go back from the first pushed view ? Woooaaaaaa.....

I guess the difference is elsewhere and deeper. No ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我很坚强 2024-12-20 23:18:44

忽略过渡/动画以及幕后的结构(aleph_null 的 alswer 提供了很好的讨论),面向用户的唯一区别是使用导航栏自动返回到前一个视图的能力。

如果您使用pushViewController,您将自动在导航栏中看到一个“后退”按钮。如果您使用 PresentModalViewController ,则您不会,并且通常必须实现自己的控件和/或回调来处理关闭控制器。

从概念上讲,模式呈现样式通常用于您无法导航的原子任务(即,您要么完成任务,要么取消任务,并且在执行其中一项或另一项之前,您无法在应用程序中执行任何其他操作)。

如果您想知道为什么会有这种差异,我不能说。就我个人而言,我认为提供统一 API 来从一个控制器转移到另一个控制器(例如 cocos2d 或 Android)的框架更有意义。

Ignoring transitions/animations and how things are structured behind the scenes (which aleph_null's alswer provides a good discussion of), the only user-facing difference is the ability to return to the preceding view automatically using the navigation bar.

If you use pushViewController you will automatically get a "Back" button in the navigation bar. If you use presentModalViewController you do not, and generally will have to implement your own controls and/or callbacks to handle dismissing the controller.

Conceptually the modal presentation style is generally used for atomic tasks that you cannot navigate away from (i.e. you either complete the task, or you cancel, and you cannot do anything else within the app until you do one or the other).

If you're wondering why have the difference in the first place, I can't say. Personally I think frameworks that provide a unified API for moving from one controller to another (like cocos2d, or Android) make a lot more sense.

本宫微胖 2024-12-20 23:18:44

最重要的区别在于语义。模态视图控制器通常指示用户必须提供一些信息或执行某些操作。此链接更深入地解释了它: http://developer .apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

这是另一个不太抽象的内容他们谈论的区别是:

“当您呈现模态视图控制器时,系统会在进行呈现的视图控制器和所呈现的视图控制器之间创建父子关系。具体来说,进行呈现的视图控制器会更新其 modalViewController属性指向其呈现的(子)视图控制器类似地,呈现的视图控制器更新其parentViewController属性以指向呈现它的视图控制器。”

另请参阅此线程:为什么“呈现模态视图控制器”?

The most important difference is about semantics. Modal view controllers typically indicate that the user has to provide some information or do something. This link explains it more in depth: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

Here's another, less abstract difference they talk about:

"When you present a modal view controller, the system creates a parent-child relationship between the view controller that did the presenting and the view controller that was presented. Specifically, the view controller that did the presenting updates its modalViewController property to point to its presented (child) view controller. Similarly, the presented view controller updates its parentViewController property to point back to the view controller that presented it."

Also see this thread: why "present modal view controller"?

邮友 2024-12-20 23:18:44

查看图像中的 viewController

  • 左上角的前 2 个 viewController(登录和提交)与 tabBarController 和 tabBarController 已断开。导航控制器
  • 其余的视图控制器都嵌入在导航控制器中。它们在某种程度上属于应用程序的自然流程。

现在你必须问自己

我是否需要每次都显示登录+提交页面?即使用户上次登录过,每次都去登录也会很痛苦。这两个屏幕确实不适合屏幕的自然流动。那么我们该怎么办呢?我们只是使用 presentViewController 以模态方式添加它们,

但是对于其余的 viewController,我们希望将它们保留在 2 个导航中,以便我们可以轻松来回,因此我们使用 PushViewController

在此处输入图像描述

有关详细信息,我建议您查看此 视频
该图片也是从这个很好的答案中挑选的。值得一看。

Take a look into the viewControllers in the image

  • The top 2 viewControllers(login & submit) at the top left are disconnected from the tabBarController & NavigationController
  • The rest of the viewControllers are embedded in a NavigationController. They somehow belong to the natural flow of the app.

Now you have to ask yourself

Do I need to always show login + submit page every time? It would be pain in the neck for the user to each time go to login even if they logged in last time. These 2 screen really don't fit the natural flow of the screens. So what do we do? We just add them modally using presentViewController

However for the rest of the viewControllers we want to keep them inside 2 navigation so we can easily go back and forth so we use pushViewController

enter image description here

For more information I recommend you to see this video
The image was also picked from this great answer. It's worthy of a look.

汹涌人海 2024-12-20 23:18:44

这就是我的经验所说的,如果你想管理视图的层次结构,最好在导航控制器中使用pushViewController。它的工作原理就像导航控制器中的一堆视图控制器。然而,如果要求只是显示在父视图控制器上执行某些操作的视图,那么最好的方法是以模态方式呈现它。
如果您需要复杂的推送弹出逻辑,总是更喜欢 PushViewController。

This is what my experience says,if you want to manage a hierarchy of views,better go for pushViewController in the navigation controller. It works like a stack of view-controllers in the navigation controller. If however the requirement is just to show a view on executing some actions on the parent view controller then the best way is presenting it modally.
If you need a complex push pop logic always prefer a pushViewController.

ぽ尐不点ル 2024-12-20 23:18:44

当您想要对数据进行某种层次表示(即向下钻取)时,可以使用 UINavigationController。他们使用一堆 UIViewController 子类来工作。每次“向下钻取”时,您只需将另一个视图控制器添加到堆栈中即可。然后,“后退”逻辑只是将视图控制器从堆栈中弹出。

您可以查看此链接:
http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/" icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/

UINavigationController are used when you want to have some sort of hierarchal representation of your data (ie drill down). They work using a stack of UIViewController subclasses. Every time you “drill down”, you simply add another view controller to the stack. Then, the “back” logic is simply a matter of popping view controllers off of a stack.

You can check out this link:
http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文