You’re previewing Ry’s Cocoa Tutorial
The Master-Detail Pattern
The previous chapter introduced the model-view-controller pattern using a
single object (
VolumeData) as the model layer. In this chapter,
we’ll upgrade our model layer to store a list of items. This may
seem like a minor addition, but it has a significant impact on every aspect of
the MVC pattern.
In the model layer, it requires a dedicated class to represent the list of objects. In the controller layer, it requires an extra controller object for managing the list of items. In the view layer, it requires a Table View component to display this list of objects to the user. The resulting application architecture is called the master-detail pattern, and it’s what we’ll be exploring in this chapter.
You can think of the master-detail pattern as a way to scale the standard MVC pattern we learned in the last chapter. Instead of a single controller, we’ll use 2 distinct objects to manage our view layer: a master controller and a detail controller. The master controller’s job is to manage the list of items, while the detail controller takes care of displaying and editing the individual items.
The detail controller only works with a single object at a time, which means
it functions exactly like the
VolumeController from the previous
chapter. Since we already know how detail controllers work, the majority of
this chapter will focus on the master controller. We’ll also be spending
quite a bit of time with Table View, which is by far the most powerful
UI component that we’ve worked with yet.
Building a complete master-detail application isn’t a trivial endeavor, and as a result, this is a relatively long chapter. However, understanding how to let the user drill down into a list of items is quite possibly the most important thing you’ll learn in Cocoa application development. It forms the basis for apps like iPhoto, Mail, Finder, and even Xcode.
Sorry, this is the end of the preview. To read the rest of this chapter, you’ll need to purchase Ry’s Cocoa Tutorial.
Sign up for my low-volume mailing list to find out when new content is released. Next up is a comprehensive Swift tutorial planned for late January.
You’ll only receive emails when new tutorials are released, and your contact information will never be shared with third parties. Click here to unsubscribe.