I have following code in my AppDelegate.swift to setup root view controller for an iOS application. But it does not work. It follows Target structure (defined under General
var window: UIWindow?
has been moved from AppdDelegate.swift to SceneDelegate.swift.
So I used rootViewController in the Scene Delegate class and it works -
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
if let tabBarController = window?.rootViewController as? UITabBarController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(identifier: "NavController")
vc.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 1)
tabBarController.viewControllers?.append(vc)
}
}
let MainViewController = mainStoryboard.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController
let nvc:rootNavigation = mainStoryboard.instantiateViewController(withIdentifier: "rootNavigation") as! rootNavigation
nvc.viewControllers = [Mainmap]
leftViewController.mainViewController = nvc
UIApplication.shared.windows.first?.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0)
UIApplication.shared.windows.first?.rootViewController = nvc
UIApplication.shared.windows.first?.makeKeyAndVisible()