【问题标题】:ViewController not loading from iOS 13.0 version onwardsViewController 未从 iOS 13.0 版本开始加载
【发布时间】:2020-09-24 02:43:50
【问题描述】:

在 iOS 13 中,我无法加载 TabBarViewController。 iOS 13.0以下版本,运行正常。

public static func updateRootVC(){

    var rootVC = UIViewController()
    let appDelegate = UIApplication.shared.delegate as! AppDelegate

    if(status == true){

        let tabBarController  = UIStoryboard(name: AppStoryboard.dashboard.rawValue, bundle: nil).instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
        appDelegate.window?.rootViewController = tabBarController

    }

    else{
        let welcomeViewController = UIStoryboard(name: AppStoryboard.main.rawValue, bundle: nil).instantiateViewController(withIdentifier: "WelcomeViewController") as! WelcomeViewController
        rootVC = UINavigationController.init(rootViewController: welcomeViewController)
        rootVC.addChild(welcomeViewController)
        appDelegate.window?.rootViewController = rootVC
    }
}

我在我的项目中手动包含了SceneDelegate,它对此有什么影响吗?

您的解决方案应该从 iOS 13.0 版本开始工作。

【问题讨论】:

  • 从 iOS 13 开始,您应该使用 SceneDelegate 而不是 AppDelegate 进行此类操作。你可以在网上找到一堆教程。

标签: ios swift ios13 appdelegate


【解决方案1】:

正如之前所评论的,因为 iOS 13 sceneDelegate 被引入来处理多个场景应用程序,所以如果你有 Scene 委托文件,那么你必须重写该函数,以便在场景委托中使用 window 属性,因为它已从 AppDelegate 中删除。

public static func updateRootVC(){
var rootVC = UIViewController()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if(status == true){
    let tabBarController  = UIStoryboard(name: AppStoryboard.dashboard.rawValue, bundle: nil).instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
    if #available(iOS 13, *) {
        UIApplication.shared.windows.first?.rootViewController = tabBarController
        UIApplication.shared.windows.first?.makeKeyAndVisible()
    }else{        
        appDelegate.window?.rootViewController = tabBarController
    }      
}else{
    let welcomeViewController = UIStoryboard(name: AppStoryboard.main.rawValue, bundle: nil).instantiateViewController(withIdentifier: "WelcomeViewController") as! WelcomeViewController
    rootVC = UINavigationController.init(rootViewController: welcomeViewController)
    rootVC.addChild(welcomeViewController)
    if #available(iOS 13, *) {
        UIApplication.shared.windows.first?.rootViewController = rootVC
        UIApplication.shared.windows.first?.makeKeyAndVisible()

    }else{        
        appDelegate.window?.rootViewController = tabBarController
    }
} 

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多