本文介绍了如何在不使用UINavigationController的情况下在新的非模型视图控制器中进行转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下似乎是一个典型的用例:使用显示登录屏幕的LoginViewController启动应用程序。用户成功登录后,您需要显示应用程序的主视图(我们称之为MainViewController)。

The following seems like a typical use case: You start the app with a LoginViewController that displays the login screen. Once the user has successfully logged in, you want to show the main view for your app (let's call it MainViewController).

您不希望将LoginViewController放入UINavigationController并随后将MainViewController推送到它上面,因为没有理由将LoginViewController保持在堆栈的底部,因为它永远不会再出现。此外,在随后的应用程序启动中,您将确定您已经拥有某种登录令牌,并且永远不会最终显示LoginViewController,因此从启动到启动导航控制器的堆栈会出现不一致。

You don't want to put the LoginViewController into a UINavigationController and subsequently push MainViewController onto it because there's no reason to keep the LoginViewController present at the bottom of the stack since it will never be shown again. Also, in subsequent launches of the app, you'll determine that you've already got a login token of some kind and will never end up showing the LoginViewController at all so there'd be inconsistency from launch to launch of the navigation controller's stack.

你也不想出于同样的原因从LoginViewController模态呈现MainViewController(如果它是模态的话会阻止LoginViewController加载)。

You also don't want to modally present MainViewController from LoginViewController for the same reason (if it's modal it would keep the LoginViewController loaded behind).

您也不想将窗口的rootViewController设置为MainViewController(之前设置为LoginViewController),因为这不允许您进行转换。

You also don't want to set the window's rootViewController to MainViewController (where it was previously set to LoginViewController) because that won't allow you have a transition.

我想对上述逻辑是否存在缺陷提出一些反馈,事实上其中一种情况是正确的?或者如果没有,那么其他人在做什么呢?

I'd like some feedback on whether my logic above is flawed and in fact one of these scenarios is the right one? Or if not, what are others doing for this scenario?

推荐答案

为什么不让MainViewController成为应用程序的根视图控制器,并呈现如果您没有登录令牌,则在启动时以模态方式启用LoginViewController?

Why not make the MainViewController your app's root view controller, and present the LoginViewController modally upon launch if you don't have a login token?

这篇关于如何在不使用UINavigationController的情况下在新的非模型视图控制器中进行转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 04:40