覆盖首先显示哪个屏幕的简单方法 iOS [英] Easy way to override which screen shows up first iOS

查看:20
本文介绍了覆盖首先显示哪个屏幕的简单方法 iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在尝试 storyboards,并且我有我的 UITableViewController 作为我的 rootViewController.现在在某些情况下,如果我的用户没有登录,我希望另一个 UIViewController 首先出现.我知道我可以对其执行 segue,但根据我的理解,TableView 仍会尝试加载,除非他们提供有关此的信息,否则这不是我想要的code>UIViewController 例如,我试图首先出现(如果 NSUserDefaults 中不存在键).

Right now I'm trying storyboards out, and I have my UITableViewController as my rootViewController. Now on some instances if my user is not logged in, I want another UIViewController to appear first. I understand I can perform a segue to it, but from my understanding the TableView will still try to get loaded, which is not what I want unless they supply info on this UIViewController that I'm trying to get to appear first (if say a key doesn't exist in NSUserDefaults) for example.

所以我的问题是,是否有一个简单的解决方案,我可以添加到我的 appDelegate 以覆盖"故事板中的 rootViewController,或者出现在它之前,然后有一个简单的按钮就可以关闭故事板中的 rootViewController ?

So my question is, is there an easy solution I can maybe add to my appDelegate to "override" the rootViewController from storyboard, or appear before it, then have a button simply on it to dismiss back to that rootViewController in storyboard?

谢谢!

推荐答案

您可以:

  • 使用不同的初始视图控制器(您可以在故事板中指定).在该视图控制器中,检查用户是否已登录.如果已登录,只需通过手动触发的 segue 直接转换到表视图控制器.如果没有,则显示登录屏幕.

  • Use a different initial view controller (you can specify this in the storyboard). In that view controller, check if the user is logged in. If they are, just transition directly to the table view controller via a manually triggered segue. If not, display the login screen.

子类 UITableViewController.在 viewDidLoad 中检查登录.如果没有,请提供一个模态登录视图控制器.

Subclass UITableViewController. Check for the login in viewDidLoad. If not, present a modal login view controller.

您可能不想在应用程序委托中执行此操作,因为这需要您手动加载故事板,这意味着不必要的代码.

You probably don't want to do it in the app delegate since that would require you to manually load the storyboard, which means unnecessary code.

这篇关于覆盖首先显示哪个屏幕的简单方法 iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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