Learn Objective-C on the Mac - Mark Dalrymple [89]
Then, with the new array controller still selected, open the Attributes Inspector, and in the Object Controller section set the Mode to Entity, and the Entity Name to MythicalPerson. Click to turn on the Prepares Content checkbox. This ensures that the controller’s content is fetched automatically when the nib loads.
Now switch to the Bindings Inspector, where we’re going to configure two bindings that will let this controller automatically get its content based on the selected MythicalBand. First, at the very bottom, open up the configuration for Managed Object Context. Choose MythBase_AppDelegate in the popup, and managedObjectContext for the Model Key Path, which should automatically turn on the Bind To checkbox. This configuration is the same as for all our array controllers, and allows them to connect to the Core Data storage. Next, in the Controller Content section, open up the Content Set binding configuration, and choose Bands in the popup, selection for the Controller Key, and members for the Model Key Path. Doing so makes the controller’s content dependent on the selected band.
Now, bring up the Mythical Bands window, and make it a bit taller, almost twice as high, so that we can fit another table view beneath the current content. Then drag over a table view from the Library, and click on it to select the table view itself (instead of the scroll view containing it, which is what is selected by default just after the drag). We’re only going to show the names of the band members here, so we only need one column in this table. Bring up the Attributes Inspector, find the Columns setting and change it to 1. Then make the column heading nicer, like you’ve done in previous chapters, by setting its title to Member Name and making it fill the width of the table. Finally, top it all off with a Band Members label, so the users know what they’re looking at. Figure 8-13 shows approximately what you should see at this point.
Now all that’s left is configure a binding for that column. Start by selecting the column. Remember, you may have to click several times to drill down to just the right depth. One handy way to avoid all this extra clicking is to control-shift-click on the column. Doing so brings up a special menu, showing the list of all the view objects at the spot you clicked: the column, and each of its superviews. Now bring up the Bindings Inspector. Open the Value configuration, select BandMembers in the popup, arrangedObjects in the Controller Key, and name in the Model Key Path, turning on the Bind To check box. Then save your work, hit Build & Run in Xcode, and you’ll see the new functionality: specifying a band for a person will add that person to the band’s members array, which you’ll see when you select the band in the Mythical Band window.
Figure 8-13. Adding band members to the Mythical Bands window
Create a Venue Window
Now it’s time to create one more window, for displaying and editing MythicalVenues, once again using the “assistant.” First go back to Interface Builder and create another empty window. Then switch back to the model file in Xcode, and -drag the MythicalVenue entity over to the new window you just created (don’t forget about ⌘Tab). Once again, the New Core Data Entity Interface assistant appears. Select Master/Detail View from the popup list, and click to enable the Search Field and Add/Remove checkboxes (again leaving the Details Fields checkbox unchecked), then click Next. The next window asks which attributes we want to display. Turn off the gigs checkboxes, and click Finish.
Finish off this window by removing the labeled NSBox that contains all its content, because we really don’t need it. Just select the box by clicking its title, then select Layout➤Unembed Objects from the menu. Save your