Learn Objective-C on the Mac - Mark Dalrymple [63]
Next, resize the remaining column so that it fills the width of the table. Do this by clicking in the table header until the entire table header is selected. Then mouse over the vertical line marking the edge of the table column header, and drag it to the right until the column fills the whole table.
Finally, let’s disable editing in the remaining column, since we don’t want the user to change the timestamp of a created object. Click on the table column until it’s selected, then bring up the Attributes Inspector (⌘1) and click to turn off the Editable checkbox. While you’re at it, click to turn off the User Resizable checkbox as well, as there’s no reason to let the user resize the table view’s only column.
At this point, the table view and its column are graphically laid out, and everything is configured except its bindings. This is a perfect time to duplicate the table you’ve just made for displaying characters, so that we can use the exact same configuration for monsters and dungeons. Click the window background, then click once on the table view to select it (along with its enclosing NSScrollView). Now press ⌘D to duplicate the table view, and drag it the new one into place at the bottom of the center view group. Then press ⌘D once again, and drag the final table view into place in the window’s bottom right corner. For both of those, you’ll of course use the blue guidelines to help you line them up properly. Figure 6-13 shows the final layout.
Figure 6-13. The final DungeonThing window layout
Create and Configure an Array Controller
Now it’s time to create an NSArrayController so that we can configure some bindings for the first set of objects, the characters. In the Library window, search for “array,” and you’ll see NSArrayController appear in the results. Drag one of these out to the main nib window, and immediately change the name shown under the new object’s icon in the main window by clicking first on the icon, then the text itself. We’ll be using this controller to provide access to the characters array, so name it “characters.” Giving this top-level nib object a unique name of its own will help a bit later on, when we’ll be adding two more array controllers to this nib.
You may recall that we added some NSArrayController outlets to DungeonThingAppDelegate. Now’s the time to connect DungeonThingAppDelegate’s characterArrayController outlet to our new array controller. Ctrl-drag from DungeonThingAppDelegate to the new “characters” array controller, and choose characterArrayController from the resulting menu.
Next, click on the array controller again and bring up the Attributes Inspector (⌘1). You’ll see some options at the top that let you fine-tune the behavior of the array controller, but for now we’ll leave them all as they are. What you do need to configure is the lower portion of the Inspector, in the Object Controller section. Make sure that Mode is set to “Class,” and that Class Name is “NSMutableDictionary.” This configuration tells the controller that the model objects it’s dealing with are instances of NSMutableDictionary, a “normal” class (rather than an Entity, which we’ll cover as a part of Core Data in Chapter 7). Below that you’ll see a table view that lists the attributes that the array controller should be able to access in the model objects. Click the “+” button below the table view, and type in “createdObject,” then click “+” again and type in “timestamp.” Figure 6-14 shows the completed attributes configuration for the array controller.
Figure 6-14. The configured attributes for our first NSArrayController
You may recognize these as the keys that we used in the code for