如何从标签栏应用程序中的app delegate跳过登录屏幕

时间:2017-09-05 18:31:55

标签: ios swift redirect

当我关闭应用程序并重新启动时,我试图跳过登录屏幕。

我得到了许多回答的问题,但没有一个带有标签栏应用程序。 所以挑战在于我有很多根视图控制器,如果尝试直接用SecondViewController分配根目录,会分散整个项目的注意力。

这是我项目的图片:

https://imgur.com/a/YoUMf

  1. 是标签栏应用
  2. 导航到索引0标签栏
  3. 登录屏幕
  4. 个人资料页面
  5. 我想跳过登录屏幕并直接显示个人资料页面,因为我的:

    if UserDefaults.standard.object(forKey: "USER_KEY_UID") != nil {
        /*provide me the correct code can be applied here with out distracting the tabbed bar in the bottom  */
    }
    

    注意:上面的代码我在appDelegete中应用

1 个答案:

答案 0 :(得分:0)

为标签栏控制器创建一个类。它应该是UITabBarController的子类

将此视为主视图控制器,并在您的app delegate中添加如下所示的登录控制器。

if UserDefaults.standard.object(forKey: "USER_KEY_UID") != nil {
        let storyboard = UIStoryboard(name: [Main Stroyboard] , bundle: nil)
        let mainVcIntial = storyboard.instantiateViewController(withIdentifier: [Main VC])
        let mainController = UINavigationController(rootViewController: mainVcIntial)
        window.rootViewController = mainController
}else{
       let storyboard = UIStoryboard(name: [loginStoryboard] , bundle: nil)
        let mainVcIntial = storyboard.instantiateViewController(withIdentifier: [Login VC])
        let mainController = UINavigationController(rootViewController: mainVcIntial)
        window.rootViewController = mainController
}
window.makeKeyAndVisible()
相关问题