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 来处理多个场景应用程序,所以如果您有场景委托文件,那么您必须将函数重写为这样才能使用 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
}
}
}
在 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 来处理多个场景应用程序,所以如果您有场景委托文件,那么您必须将函数重写为这样才能使用 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
}
}
}