如何在下载后仅在Swift中显示ViewController?

问题描述 投票:0回答:2

我正在创建一个具有Onboarding功能的应用程序。此入职仅在特定目的的ViewController上进行,这就是为什么我只希望ViewController在下载应用程序后显示出来。(主应用程序仅包含一个ViewController)

这是我到目前为止所做的:

1)我删除情节提要文件中的情节提要入口点

2)输入两个ViewController的每个故事板的ID

3]在AppDelegate文件中编码,仅在下载后首次出现的ViewContoller应该出现

我的问题:在模拟器上运行应用程序时,它仅显示黑屏

我已经确保标识符和情节提要的名称正确。

(在我的AppDelegate.swift文件下面)>

import UIKit
import Firebase
import FirebaseDatabase
import paper_onboarding


@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()


        window = UIWindow(frame: UIScreen.main.bounds)

        let sb = UIStoryboard(name: "Main", bundle: nil)
        var initialViewController = sb.instantiateViewController(withIdentifier: "Onboarding")



        let userDefaults = UserDefaults.standard

         if userDefaults.bool(forKey: "onboardingComplete") {
           initialViewController = sb.instantiateViewController(withIdentifier: "MainApp")
          }


        window?.rootViewController = initialViewController
        window?.makeKeyAndVisible()




        return true

    }

    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }


}
``




我正在创建一个具有Onboarding功能的应用程序。该入职仅出于特定目的在ViewController上进行,这就是为什么我只希望ViewController在...

ios swift uiviewcontroller viewcontroller appdelegate
2个回答
0
投票

对于黑屏:


0
投票

此问题的解决方案不是使用AppDelegate.swift文件,而是使用SceneDelegate.swift文件。

© www.soinside.com 2019 - 2024. All rights reserved.