In iOS 13, I was unable to load the TabBarViewController
. Below the iOS 13.0 version, it's working fine.
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?
Your solution should work from version iOS 13.0 onwards.
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.
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
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.