brunch

You can make anything
by writing

C.S.Lewis

by 으아한구렝 Feb 22. 2018

presentedViewController

그 애매함에 대해

앱스킴이나 푸시를 통해서 앱으로 진입할 때, 앱의 기존 상태는 어떻게 관리해줘야하는가에서 시작되었습니다. 이번에 정리한 브런치 iOS앱의 정책은 에디팅 상태(글, 작가신청)에서 아직 저장되지 않은 수정사항이 있으면, 사용자에게 진행 여부를 묻도록 하고, 그 외의 presentedViewController는 dismiss 후 진행하도록 합니다. 여기까지 정하고 나니 아래의 문제들에 대한 답이 헷갈리기 시작했습니다.


기본 조건.

MainViewController - Container

NavigationController - Child of MainViewController

DiscoverViewController - Root of NavigationController


1. ANavigationController - Present on MainViewController

MainViewController.presentedViewController는? - ANavigationController

NavigationController.presentedViewController는? - ANavigationController

NavigationController.topViewController는? - DiscoverViewController

NavigationController.visibleViewController는? - ANavigationController.topViewController

DiscoverViewController.presentedViewController는? - ANavigationViewController

NavigationController를 교체하면 어떻게 되나? - ANavigationViewController는 유지됨. ANavigationViewController를 dismiss 하면 교체된 NavigationController가 나타남.


2. BNavigationController - Present on DiscoverViewController

MainViewController.presentedViewController는? - BNavigationController

NavigationController.presentedViewController는? - BNavigationController

NavigationController.topViewController는? - DiscoverViewController

NavigationController.visibleViewController는? - BNavigationController.topViewController

DiscoverViewController.presentedViewController는? - BNavigationController

NavigationController를 교체하면 어떻게 되나? - BNavigationController는 유지됨. BNavigationController를 dismiss 하면 교체된 NavigationController가 나타남.


3. CViewController - Present on BNavigationController.topViewController

MainViewController.presentedViewController는? - BNavigationController

NavigationController.presentedViewController는? - BNavigationController

NavigationController.topViewController는? - DiscoverViewController

NavigationController.visibleViewController는? - CViewController

DiscoverViewController.presentedViewController는? - BNavigationController

BNavigationController.presentedViewController는? - CViewController

BNavigationController.topViewController.presentedViewController는? - CViewController

NavigationController를 교체하면 어떻게 되나? - CViewController, BNavigationController는 유지됨. CViewController를 dismiss하고, BNavigationController를 dismiss하면 교체된 NavigationController가 나타남.

CViewController.presentingViewController는?


중첩된 presentedViewController가 있을 경우 dismiss 처리를 확인하기 위한 실험이었는데 문서에 언급이 있었습니다.

func dismiss(animated flag: Bool, completion: (() -> Void)? = nil)

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.


visibleViewController도 마찬가지입니다.

var visibleViewController: UIViewController? { get }

The currently visible view can belong either to the view controller at the top of the navigation stack or to a view controller that was presented modally on top of the navigation controller itself.
좋은 헛수고였습니다. 어리석은 이여.
keyword
작가의 이전글 2. Observables
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari