본문 바로가기

Codes Travel/iOS Boost Course #2019

UINavigationController ?

안녕하세요 :)

iOS 개발자 리치(rich_iosdev) 입니다.

 

공유해드릴 내용은 UINavigationController 입니다.

UINavigationController?

UINavigationController는 Navigation Interface에서 하나 이상의 자식 ViewController를 관리하는ContainerViewController 입니다.

 

  • Navigation Interface에서는 오직 하나의 자식 ViewController만 화면에 보여집니다.
  • ViewController 화면에서 하나의 아이템을 선택하게 되면 해당 ViewController를 숨기면서 화면 전환 애니메이션과 함께 새로운 ViewController가 나타나게 됩니다 (push).
  • Interface 상단에 위치한 Navigation Bar의 'Back' Button을 탭하면 가장 상단에 위치한 ViewController가 제거되면서 바로 아래 위치한 ViewController가 나타나게 됩니다.

 

UINavigationController

위 이미지의 좌측 첫번째 Settings ViewController 화면에서 General 아이템을 선택하면 두번째 화면인 General ViewController 가 화면에 나타나게 되고 (Push), Setting 화면으로 돌아갈 수 있는 Back (< Settings) 버튼이 Interface 좌측 상단의 Navigation Bar에 나타납니다. 세번째 화면도 동일하게 작동합니다.

 

Navigation Stack?

Navigation Controller의 오브젝트는 자식 ViewController들을 순서대로 정렬된 배열 구조로 관리하는데 이 구조를 Navigation Stack 이라고 표현합니다.

 

  • Navigation Stack 구조에 있는 첫번째 ViewController를 rootViewController라고 하며 Navigation Stack의 가장 바닥에 위치한 ViewController임을 표현합니다.
  • Navigation Stack 구조의 가장 마지막에 위치한 ViewController는 Stack에서 가장 상위에 위치한 ViewController이며, 현재 화면에 보여지는 ViewController 입니다.
  • Segues 또는 클래스 메서드들을 이용해서 Navigation Stack 구조에 ViewController를 add (추가) 할 수 있고, Navigation Stack 구조에 있는 ViewController를 remove(제거) 할 수 있습니다.
  • 앱을 사용하는 User도 Navigation Bar의 Back Button과 left-edge swipe gesture를 사용하여 가장 상위에 있는 (화면에 보여지고 있는) ViewController를 제거 할 수 있습니다.

 

UINavigation Bar & UIToolbar & Delegate?

Navigation Controller가 Interface 상단의 Navigation Bar와 하단의 Toolbar (optional) 를 관리하며, Delegate 객체와 함께 동작합니다.

  • Navigation Bar는 Navigation Controller가 관리하는 모든 ViewController의 상단에 보여지며, 최 상위 ViewController가 변경 될 때마다 Navigation Controller가 Navigation Bar를 업데이트 합니다.
  • isToolbarHidden property 가 false 일 때, Navigation Bar와 동일하게 최 상위 ViewController가 변경 되면, Navigation Controller에서 Toolbar를 업데이트 합니다. 
  • Navigation Controller는 Delegate 객체와 함께 동작을 합니다. Delegate 객체는 push(add) / pop(remove) 메서드를 재정의 하여 사용 할 수 있도록 하고, Custom한 화면 전환 애니메이션을 제공하며, 마지막으로 Navigation Interface의 기본 Orientation 을 설정 가능하게 합니다. 

UINavigationBar 와 UIToolbar 관련된 내용은 별도로 포스팅 하겠습니다.

 

혹시 내용이 잘못된 부분이 있다면 댓글로 달아주세요!

확인해서 꼭 수정하겠습니다.

 

끝까지 읽어주셔서 정말 감사합니다.

 

Reference

 

UINavigationController - UIKit | Apple Developer Documentation

Class UINavigationController A container view controller that defines a stack-based scheme for navigating hierarchical content. DeclarationOverviewA navigation controller is a container view controller that manages one or more child view controllers in a n

developer.apple.com