7.4 · Navigation, tab, split and page controllers
Most apps are a few container controllers arranged around your screens. Knowing how each one owns its children is how you avoid state that mysteriously resets.
Mental model. A container owns its children’s lifetime and layout, not their content. Each screen still decides what it shows; the container decides which one is on screen and how you move between them.
Stacks and tabs
The two containers almost every app uses.
- How does UINavigationController manage its stack, and where do the bar items and back button come from?
A navigation controller holds an ordered array, viewControllers, with topViewController on screen. pushViewController(_:animated:) adds one, popViewController… - How do UITabBarController, UISplitViewController and UIPageViewController differ, and what loads when?
A tab bar controller shows one of its child controllers at a time, switched from the bar. Each tab is usually its own navigation controller, so each keeps an…
More in UIKit
- 7.1 · Hit testing, the responder chain and gesture recognisers
- 7.2 · UIView and CALayer, frame, bounds and center
- 7.3 · View controller lifecycle, containment, presentation and transitions
- 7.5 · Compositional layout, diffable data sources, cell reuse and prefetching
- 7.6 · UITableView, still asked and still everywhere
- 7.7 · Trait collections, size classes, safe area, keyboard and appearance
- 7.8 · Keyboard shortcuts, pointer, Apple Pencil and multitasking
- 7.9 · Hosting SwiftUI in UIKit and UIKit in SwiftUI
- 7.10 · Initialisers, stack views, scroll views and modern buttons
- 7.11 · Layout passes, retain cycles and menus
- 7.12 · Refreshing diffable cells, outlines and carousel layouts
- 7.13 · View-tree exercises and long navigation stacks