Theoretical Overview
View controllers are an essential part of any iOS application, no matter how small, big, simple, or complex. They provide the “glue-logic” between the data model of your app and the user interface.
Broadly speaking, there are two kinds of view controllers:
- Content view controllers: These are responsible for displaying and managing visible content.
- Container controllers: These manage content view controllers, and they’re responsible for the overall structure and flow of the app.
A container controller may have some visible component of its own, but basically functions as a host for content view controllers. Container controllers serve to “traffic” the comings and goings of content view controllers.
UINavigationController, UITabBarController and UIPageViewController are examples of container view controllers that ship with the iOS SDK. Consider how the three are different in terms of the application flows that they give rise to. The navigation controller is great for a drill-down type app, where the selection the user makes in one screen affects what choices he’s presented with in the next screen. The tab bar controller is great for apps with independent pieces of functionality, allowing convenient toggling by simply pressing a tab button. Finally, the page view controller presents a book metaphor, allowing the user to flip back and forth between pages of content.
The key thing to keep in mind here is that an actual screenful of content being presented through any of these container view controllers itself needs to be managed, both in terms of the data it is derived from (the model) and the on-screen presentation (the view), which would again be the job of a view controller. Now we’re talking about content view controllers. In some apps, particularly on the iPad because its larger screen allows more content to be shown at once, different views on the screen might even need to be managed independently. This requires multiple view controllers onscreen at once. All of this implies that the view controllers in a well-designed app should be implemented in a hierarchical manner with both container and content view controllers playing their respective roles.
コメント
コメントを投稿