Полностью черный экран при настройке начального вида контроллера в AppDelegate - PullRequest
3 голосов
/ 19 января 2020

Все, что я хочу сделать, это go на экран входа в систему, если пользователь = ноль. В противном случае он переходит в основной / домашний раздел приложения, который состоит из первого контроллера представления панели вкладок

Вот мой делегат приложения:

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    if Auth.auth().currentUser == nil && !UserDefaults.standard.bool(forKey: "hasViewedWalkthrough") {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "WalkthroughViewController") as? WalkthroughViewController
        self.window?.rootViewController = initialViewController


    } else if Auth.auth().currentUser == nil && UserDefaults.standard.bool(forKey: "hasViewedWalkthrough") {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "loginViewController") as? LoginViewController
        self.window?.rootViewController = initialViewController

    } else {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "homeTabBarController") as? MainTabBarViewController
        self.window?.rootViewController = initialViewController

    }

    self.window?.makeKeyAndVisible()
    return true
}

Я не могу добраться до экран регистрации или входа. Меня всегда ведут на главный экран. Я знаю, что экраны воспроизводятся нормально, если я вручную установил их в качестве начальных контроллеров представления в раскадровке.

Я пробовал множество решений, и ни одно из них не работает.

Обновление enter image description here

1 Ответ

1 голос
/ 20 января 2020

Попробуйте:

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController = storyBoard.instantiateViewControllerWithIdentifier("homeTabBarController") as? TabBarViewController // whatever your swift file is called 
        self.window?.rootViewController = storyBoard

используйте этот код для каждого оператора для оператора if, очевидно, измените имена контроллеров представления на логин, соответственно.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...