본문 바로가기
iOS Swift/Study

스토리보드 없이 Custom Navigation Controller 연결하기

by 야고이 2024. 4. 22.
728x90

240422

 

1. Navigation Controller 생성

 

 

가장 처음 보이는 화면과 연결 하는 코드

let vc = ViewController() // 가장 처음 보이는 controller
self.pushViewController(vc, animated: true) // 전체 화면으로 보이게 함

 

2. SceneDelegate에 RootView 등록 

스토리보드 없는 codebase UI 셋팅은 ScenDelegate 파일에 아래 코드를 추가해 주었었다

guard let windowScene = (scene as? UIWindowScene) else { return }
        
        window = UIWindow(windowScene: windowScene)
	window?.rootViewController = ViewController() // 원하는 뷰컨트롤러로 변경해주기
        window?.makeKeyAndVisible()

 

 

네비게이션 컨트롤러를 연결하려면 rootViewController 에 NavigationController 를 생성해 준다

guard let windowScene = (scene as? UIWindowScene) else { return }
        
        window = UIWindow(windowScene: windowScene)
        window?.rootViewController = MainNavigationController()
        window?.makeKeyAndVisible()

상단에 네비게이션으로 <Back  이 생긴걸 볼 수 있다

버튼을 눌러서 다른 뷰로 이동하는건 다음 포스팅에서 다뤄보겠다

728x90

댓글