Database Reference
In-Depth Information
-add: action, and the remove button will be connected to the -remove: action on
the recipe's NSArrayController . These buttons can be connected to their actions
by holding down the Control key, clicking the button, and dragging from the
selector sent action to the NSArrayController . With these small changes, we can
now add and remove recipe entities at will.
Adding the Recipe Details
Now that the source list in place, it's time to add the details about the recipe.
These details (the name, serves, desc, and type) tie to the now-valid selection
controller key on the recipe's NSArrayController . As a result, when a user clicks
in the list, the relevant details of the recipe are selected.
The first two items are text fields, the third and fifth elements are pop-up
boxes, and the final element is a text area, as shown in Figure 22, The main
window , on page 127 . With the exception of the pop-up boxes for the type and
author, these details are configured in a very similar way. All of them have a
value binding associated with the recipe's NSArrayController object through a
controller key of selection and a model key path of name , serves , and desc , as
appropriate. One tip with regard to the text area: be sure to turn off the Rich
Text setting. When this setting is on, the field expects an NSAttributedString
instead of an NSString , which can cause confusion (see Figure 24, Remember
to turn off the Rich Text setting , on page 130 ). Additionally, in order to be good
citizens, we should drag an NSNumberFormatter to the Serves text field and con-
figure it to allow only whole numbers.
The pop-up boxes are a little more complex. Although each pop-up box is
associated with the selected recipe, we need to populate the entire list of
recipes with values. The values belong to other entities on the other side of
relationships. While we want to, for example, show the selected recipe type,
what we really need to display is the name of the recipe type being selected.
Fortunately, this is a fairly common use case, and there are built-in tools to
handle it. Each pop-up box is designed to be associated with an NSArrayController .
And each NSArrayController references the entities we want to appear in the pop-
up boxes. Furthermore, we can define each pop-up box to display a specific
value from those entities.
As shown in Figure 25, Manual data entry for the combo box , on page 131 ,
starting with the Type pop-up box, we need to set three sections of values.
• In the Content section, we bind to the type NSArrayController with a Controller
Key setting of arrangedObjects. This step instructs the pop-up box to
access the type NSArrayController for the objects it is to work with.
 
 
Search WWH ::




Custom Search