2017-06-10 82 views
0

我希望你能帮助我。我不知道自己做错了什么,我已经为代码做了很多圈。我尝试的是,当用户通过身份验证时,它被重定向到tabcontroller,但视图不加载(黑屏加载)。奇怪的是,它在黑色加载视图中加载顶层菜单。 Storyboard的附加图像和假定的加载视图。非常感谢您uiTabBarController视图中的黑色屏幕

func application(_ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: 
    [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    UIApplication.shared.statusBarStyle = .lightContent 

    let storyBoard: UIStoryboard = UIStoryboard(name:"Main", bundle: Bundle.main) 

    if Session.isLoggedIn { 
    print("User already logged In") 
    let tabBarController = storyBoard.instantiateViewController(withIdentifier: "TabBarBuyerController") 
    self.window?.makeKeyAndVisible() 
    self.window?.rootViewController = tabBarController 
    } else { 
    print("New User") 
    let loginViewController = storyBoard.instantiateViewController(withIdentifier: "LoginViewController") 
    self.window?.makeKeyAndVisible() 
    self.window?.rootViewController = loginViewController 
} 

    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } 

Main StoryBooard picture

Loaded view

+0

我觉得你使用Swft和界面生成器很糟糕。直到十年后,这一切都不易调试。使用Objective-C并以编程方式创建您的视图,然后您就可以找出它 – Loxx

回答

0

问题是,你不TabBarViewController设置的viewController。使用下面的方法显示TabBarViewController在AppDelegate

func showHeadlineTabBarViewController() { 

    let storyboard = UIStoryboard(name: "Main", bundle: nil) 

    let FirstViewController: UIViewController? = storyboard.instantiateViewController(withIdentifier: String(describing: FirstViewController.self)) 
    let FirstViewControllerNC = UINavigationController(rootViewController: FirstViewController!) 

    let secondViewController: UIViewController? = storyboard.instantiateViewController(withIdentifier: String(describing: SecondViewController.self)) 
    let secondViewControllerNC = UINavigationController(rootViewController: secondViewController!) 

    let tabBarController = storyBoard.instantiateViewController(withIdentifier: "TabBarBuyerController") 
    tabBarController.viewControllers = [FirstViewControllerNC, secondViewControllerNC] 

    window?.rootViewController = tabBarController 
    window?.makeKeyAndVisible() 
}