简体   繁体   English

Swift:在SplitViewController之前有一个登录屏幕

[英]Swift: Having a Login Screen before SplitViewController

I understand that it is not allowed and UISplitViewController should always be root controller. 我知道这是不允许的,UISplitViewController应该始终是根控制器。

How can I have a login screen before splitViewController? splitViewController之前如何显示登录屏幕? It seems to be a very common problem. 这似乎是一个非常普遍的问题。
I am new to iOS so any example will be much appreciated. 我是iOS的新手,所以任何示例都将不胜感激。
Tried updating viewDidLoad() of MasterViewController: 尝试更新MasterViewController的viewDidLoad():

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        if (!appDelegate.loggedIn) {
            // display the login form
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let login = storyboard.instantiateViewControllerWithIdentifier("LoginVC") as UIViewController
            self.presentViewController(login, animated: false, completion: { () -> Void in
                // user logged in and is valid now
                //self.updateDisplay()
            })
        } else {
            //updateDisplay()
        }

But it threw me a warning: arning: Attempt to present <LoginViewController: 0x7f8ef8f12c80> on <SideBarViewController: 0x7f8ef8d9faf0> whose view is not in the window hierarchy! 但是它给了我一个警告: arning: Attempt to present <LoginViewController: 0x7f8ef8f12c80> on <SideBarViewController: 0x7f8ef8d9faf0> whose view is not in the window hierarchy!

Make your initial view controller the split view controller. 使您的初始视图控制器成为拆分视图控制器。 In its viewDidLoad or viewDidAppear methods or whatever makes sense, check that the user is logged in. If the user isn't logged in, segue modally WITHOUT animation to your login view controller. 在其viewDidLoadviewDidAppear方法或任何有意义的方法中,检查用户是否已登录。如果用户未登录,则以模态方式将没有动画的字符串选择到登录视图控制器中。 This will all happen without the user noticing and will allow the storyboard setup you want. 这一切都会在用户不注意的情况下发生,并允许您设置所需的情节提要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM