Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用故事板时带有sceneDelegate的黑屏_Ios_Swift_Xcode_Uiscenedelegate - Fatal编程技术网

Ios 使用故事板时带有sceneDelegate的黑屏

Ios 使用故事板时带有sceneDelegate的黑屏,ios,swift,xcode,uiscenedelegate,Ios,Swift,Xcode,Uiscenedelegate,首先显示AuthViewController(也称为根) 然后是一个带有tabBarController的黑屏,但上面没有项目 有什么问题吗 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowSce

首先显示AuthViewController(也称为根) 然后是一个带有tabBarController的黑屏,但上面没有项目

有什么问题吗

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.windowScene = windowScene

        if let user = Auth.auth().currentUser {
            FirestoreServices.shared.getUserData(user: user) { (result) in
                switch result {
                case .success(let muser):
                    let mainTabBar = MainTabBarViewController()
                    mainTabBar.currentUser = muser
                    mainTabBar.modalPresentationStyle = .fullScreen
                    self.window?.rootViewController = mainTabBar
                case .failure(_):
                    self.window?.rootViewController = AuthViewController()
                }
            }
        } else {
            self.window?.rootViewController = AuthViewController()
        }
        window?.makeKeyAndVisible()
    } 

编辑:您需要从故事板实例化,因为您正在使用故事板。 您需要使用windowScene初始化窗口变量窗口

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let windowScene = (scene as? UIWindowScene) else { return }

        window = UIWindow(windowScene: windowScene)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        if let user = Auth.auth().currentUser {
            FirestoreServices.shared.getUserData(user: user) { (result) in
                switch result {
                case .success(let muser):
                    let mainTabBar = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! TabViewController
                    mainTabBar.currentUser = muser
                    mainTabBar.modalPresentationStyle = .fullScreen
                    self.window?.rootViewController = mainTabBar
                    print("BLA BLA \(String(describing: self.window?.frame))")
                case .failure(_):
                    let authVC = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! AuthViewController
                    self.window?.rootViewController = authVC
                }
            }
        } else {
            let authVC = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! AuthViewController
            self.window?.rootViewController = authVC
        }
        window?.makeKeyAndVisible()
    } 

编辑:您需要从故事板实例化,因为您正在使用故事板。 您需要使用windowScene初始化窗口变量窗口

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let windowScene = (scene as? UIWindowScene) else { return }

        window = UIWindow(windowScene: windowScene)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        if let user = Auth.auth().currentUser {
            FirestoreServices.shared.getUserData(user: user) { (result) in
                switch result {
                case .success(let muser):
                    let mainTabBar = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! TabViewController
                    mainTabBar.currentUser = muser
                    mainTabBar.modalPresentationStyle = .fullScreen
                    self.window?.rootViewController = mainTabBar
                    print("BLA BLA \(String(describing: self.window?.frame))")
                case .failure(_):
                    let authVC = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! AuthViewController
                    self.window?.rootViewController = authVC
                }
            }
        } else {
            let authVC = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! AuthViewController
            self.window?.rootViewController = authVC
        }
        window?.makeKeyAndVisible()
    } 

我在帖子中更新了代码。你的回答对我没有帮助(如果你不使用情节提要,这是可行的,但我需要使用情节提要如果你使用情节提要,第一个代码就可以了。我刚刚测试了它。确保情节提要中没有任何设置为初始视图控制器的ViewController(不应该有箭头指向它)从情节提要中删除了箭头,但问题并没有消失,现在它显示一个黑屏,半秒钟后用TabBarOkay显示一个黑屏,我已经更新了我的答案。如果使用情节提要,你需要从情节提要中实例化你的ViewController。我更新了帖子中的代码。你的答案对我没有帮助(如果您不使用情节提要,则此操作有效,但我需要使用情节提要如果您使用情节提要,则第一个代码将有效。我刚刚测试了它。请确保情节提要中没有任何设置为初始视图控制器的ViewController(不应有箭头指向它)从情节提要中删除了箭头,但问题并未消失,现在它显示了一个黑屏,半秒钟后使用TabBarOkay显示了一个黑屏,我已更新了我的答案。如果使用情节提要,则需要从情节提要中实例化ViewController。