[英]ViewController not loading from iOS 13.0 version onwards
In iOS 13, I was unable to load the TabBarViewController
.在 iOS 13,我无法加载
TabBarViewController
。 Below the iOS 13.0 version, it's working fine.在 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
}
}
I manually included SceneDelegate
inside my project, does it have any impact on this?我在我的项目中手动包含
SceneDelegate
,它对此有什么影响吗?
Your solution should work from version iOS 13.0 onwards.您的解决方案应从版本 iOS 13.0 开始运行。
as commented before since iOS 13 sceneDelegate is introduced to handle multiple scene apps so if you have Scene delegate file then you must rewrite the function as this to use the window property in the scene delegate since is removed from AppDelegate.正如之前评论的那样,因为 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.