You are trying to mix the understanding of Views with ViewControllers, which sometimes we don't pay attention to.
Are all the view controllers present on the phone window simultaneously one below the other
from rendering point of view, Window hosts views on top of it, not the view controllers. So when a navigation stack is generated through push/pops, a window host the view of navigation controller which is it's root controller object.
Navigation controller object itself comprise of a UINavigationBar
and a content view
where it host the views of child controllers.
Now comes the question, how the hierarchy of view's and view controller's are maintained. UINavigationController
host a single view at a time, so even if there are multiple controller's on stack, only top most controller's view is loaded in the view hierarchy. So view stack is something like
window->navigationControllerView->topMostControllerView
As for view controller's hierarchy, they are maintained on stack and stays alive unless a pop message is sent to navigation controller. Sometimes they can be destroyed on receiving memory warnings. Refer the Documentation for other details
To illustrate this, i have generated a simple stack trace. If you look at the object 0x7a6cfd60
, this is the view of top most controller MyDocumentsVC (look at the bottom line) and is present as the single subview of UIViewControllerWrapperView
which is nothing but the content view of navigation controller.
(lldb) po [[self.navigationController view] subviews]
<__NSArrayM 0x7bad3bf0>(
<UINavigationTransitionView: 0x7bad3a10; frame = (0 0; 768 1024); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x7bad3bc0>>,
<UINavigationBar: 0x7b960780; frame = (0 20; 768 44); opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0x7a69ec40>; layer = <CALayer: 0x7b960300>>
)
(lldb) po [[[[self.navigationController view] subviews] objectAtIndex:0] subviews]
<__NSArrayM 0x7baf59f0>(
<UIViewControllerWrapperView: 0x7a6c2290; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0x7a6c2360>>
)
(lldb) po [[[[[[self.navigationController view] subviews] objectAtIndex:0] subviews] objectAtIndex:0] subviews]
<__NSArrayM 0x7a6ec3f0>(
<UIView: 0x7a6cfd60; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0x7a6cfdd0>>
)
(lldb) po [self.navigationController viewControllers]
<__NSArrayI 0x7a6e9c20>(
<ViewController: 0x7b956820>,
<MyDocumentsVC: 0x7b96bc30>
)
(lldb) po [[[self.navigationController viewControllers] objectAtIndex:0] view]
<UIView: 0x7a6b68c0; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0x7a6b6930>>
(lldb) po [[[self.navigationController viewControllers] objectAtIndex:1] view]
<UIView: 0x7a6cfd60; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0x7a6cfdd0>>