更改iOS窗口的根视图控制器 [英] Changing root view controller of a iOS Window

查看:417
本文介绍了更改iOS窗口的根视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS窗口的根视图控制器通常在开头一次初始化为标签栏控制器或导航控制器吗?是否可以在应用程序中多次更改根视图控制器?

Is the root view controller of a iOS Window usually initialized once in the beginning to a tab bar controller or navigation controller? Is it okay to change the root view controller multiple times within an app?

我有一个基于用户操作的顶视图不同的场景。我正在考虑使用导航控制器,顶视图控制器具有启动画面的图像,并根据需要按下/弹出视图控制器。或者,我可以继续更改窗口的顶视图控制器。哪种方法更好?

I have a scenario where the top view is different based on user action. I was thinking of having a navigation controller with the top view controller having the image of the splash screen, and pushing/popping view controllers as required. Alternately, I can keep changing the window's top view controller. Which will be a better approach?

推荐答案

更常见的是使用呈现的视图控制器( presentViewController:动画:完成:)。您可以根据需要拥有尽可能多的这些,有效地出现在(并且基本上替换)根视图控制器之前。如果你不想要,或者有可能,就没有任何动画。您可以关闭显示的视图控制器以返回到原始根视图控制器,但您不必;如果您愿意,所呈现的视图控制器可以永远存在。

It is more usual to use a "presented view controller" (presentViewController:animated:completion:). You can have as many of these as you like, effectively appearing in front of (and basically replacing) the root view controller. There doesn't have to be any animation if you don't want, or there can be. You can dismiss the presented view controller to go back to the original root view controller, but you don't have to; the presented view controller can just be there forever if you like.

这是我书中提供的视图控制器部分:

Here's the section on presented view controllers from my book:

http://www.apeth.com/iOSBook/ch19.html#_presented_view_controller

在此图表中(从该章的前面部分开始),呈现的视图控制器已完全接管了应用程序界面;根视图控制器及其子视图不再在界面中。根视图控制器仍然存在,但这是轻量级的并不重要。

In this diagram (from earlier in that chapter), a presented view controller has completely taken over the app interface; the root view controller and its subviews are no longer in the interface. The root view controller still exists, but this is lightweight and doesn't matter.

这篇关于更改iOS窗口的根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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