iOS/iOS SeSAC 2기 TIL

[iOS swift] Scenedelegate에서 시작화면 지정하는 코드

Developer-Michelle 2022. 8. 27. 14:25

[iOS swift] Scenedelegate 에서 시작화면 지정하는 코드

 

Case 1. navigation을 달고 있는 HomeViewController에서 시작하는 앱

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let scene = (scene as? UIWindowScene) else { return }

        window = UIWindow(windowScene: scene)

        

        let viewController = HomeViewController()

        let navigationController = UINavigationController(rootViewController: viewController)

        window?.rootViewController = navigationController

        window?.makeKeyAndVisible()

    }

 

 

 

Case 2.  TabbarViewController에서 시작하는 앱

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let scene = (scene as? UIWindowScene) else { return }

        window = UIWindow(windowScene: scene)

        window?.rootViewController = TabbarViewController()

        window?.makeKeyAndVisible()

    }