UINavigationController
has 3 controllers that all sound very similar to me: topViewController
, visibleViewController
, and presentedViewController
.
Which scenarios do you use each of these controllers in?
UINavigationController
has 3 controllers that all sound very similar to me: topViewController
, visibleViewController
, and presentedViewController
.
Which scenarios do you use each of these controllers in?
pushViewController(_:animated:)
method. Pushes the previous controller out of it's way and replaces it. pushViewController(_:animated:)
you use UIViewController's present(_:animated:completion:)
method. Note: Presented view controllers are also referred to as modal view controllers and can be used WITHOUT a UINavigationController.Example:
In general it seems like visibleViewController is more useful since it will tell you what view is currently showing regardless of if it was pushed or presented.
presentedViewController
is the current modal presented on screen.
topViewController
is view controller on top of the navigation stack (see viewControllers()
method) and visibleViewController
is the currently displayed view controller on screen (can be either a controller, a modal, a UINavigationController
, a UITabbarController
, etc).
TopViewController is the topmost VC in the navigation stack. OR the View controller which was pushed last.
PresentedViewController is the viewController presented modally from the navigationController. It is not part of NaivagationController's horizontal stack, but a viewController presented over it.
Of these two viewControllers, the one that is visible to the user will be the visibleViewController of the navigationController.