Graphics Programs Reference
In-Depth Information
For the More Curious: View Controller Relationships
The relationships between view controllers are important for understanding where and how
a view controller's view appears on the screen. Overall, there are two different types of re-
lationships between view controllers:
parent-child
relationships and
presenting-presenter
relationships. Let's look at each one individually.
Parent-child relationships
Parent-child relationships are formed when using
view controller containers
. Examples of
view controller containers are
UINavigationController
,
UITabBarControl-
identify a view controller container because it has a
viewControllers
property that is
an array of the view controllers it contains.
A view controller container is always a subclass of
UIViewController
and thus has a
view
. The behavior of a view controller container is that it adds the views of its
viewControllers
as subviews of its own view. A container has its own built-in inter-
face, too. For example, a
UINavigationController
's
view
shows a navigation bar
and the view of its
topViewController
.
View controllers in a parent-child relationship form a
family
. So, a
UINavigationCon-
troller
and its
viewControllers
are in the same family. A family can have mul-
tiple levels. For example, imagine a situation where a
UITabBarController
contains a
UINavigationController
that contains a
UIViewController
. These three view
controllers are in the same family (
Figure 13.6
). The container classes have access to their
children through the
viewControllers
array, and the children have access to their an-
cestors through four properties of
UIViewController
.
Figure 13.6 A view controller family