Swift

Swift - UIViewController의 역할

garlic 2020. 12. 21. 10:00

UIViewController의 핵심 기능!

  1. Updating the contents of the views, usually in response to changes to the underlying data.

  2. Responding to user interactions with views. 

  3. Resizing views and managing the layout of the overall interface.

  4. Coordinating with other objects—including other view controllers—in your app.

*핵심기능 해석

  1. 일반적으로, 하위 데이터들의 변경에 따라 view들의 컨텐츠들을 업데이트 함.
  2. view를 통한 유저의 interaction에 반응함.
  3. 뷰들을 리사이징하고, 전체 인터페이스의 레이아웃을 관리한다
  4. 앱 내의 다른 view controller을 포함한 객체들과 협업한다.

총 정리

다들 Storyboard를 통해 UI를 그려보셨다면 최소 한번쯤 UIViewController(=이하 VC)를 사용해 보았을 것이다. VC는 흔히 사용되는 MVC 패턴에서 Controller의 역할을 한다.

 

  1. 앱은 모두 VC으로 이루어져 있다.

  2. VC은 View를 최소 하나 이상을 가진다.

    1. VC는 내부에 있는 view들의 계층구조를 관리한다.

  3. ViewController 객체를 생성해보면, 기본적으로 rootView라는 View가 들어있을 것이다. 모든 view들은 root view 내부에 들어가 있어야 하므로, view 계층구조 (=hierarchy)에서 container 역할을 한다.

  4. View와 관련된 Notification 들을 처리한다.(=뷰의 생성, 소멸, 이벤트 등) Ex) ViewDidLoad(), ViewWillAppear()와 같은 method들

  5. 사용자의 모든 이벤트는 ViewController가 받는다. 그 후에 관련 action이나 Delegate로 처리한다.

  6. View와 Model 사이에서 중재자 역할을 한다.

 

참고 링크 :
developer.apple.com/documentation/uikit/uiviewcontroller
 

Apple Developer Documentation

 

developer.apple.com