繁体   English   中英

ViewController 未从 iOS 13.0 版本开始加载

[英]ViewController not loading from iOS 13.0 version onwards

在 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 被引入来处理多个场景应用程序,所以如果你有场景委托文件,那么你必须重写 function ,因为它已从 AppDelegate 中删除,因此在场景委托中使用 window 属性。

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
    }
} 

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM