Database Reference
In-Depth Information
display its headers and its vertical scroll bar, and hide the horizontal scroll
bar. We enter the column headings as Name, Quantity, and Unit of Measure.
Just as we did in the recipe source list, we bind the values for each column
in the NSTableView to our recipe ingredients' NSArrayController using the controller
key arrangedObjects and using the appropriate model key paths: name , quantity ,
and unitOfMeasure . The Quantity column (or, more specifically, the table cell in
the Quantity column) should also have an NSNumberFormatter assigned to it so
that the quantity is properly formatted for the value that it holds. Once those
are configured, we can see the recipe ingredients for the selected recipe.
Remember that we configured the recipe ingredients' NSArrayController to feed
off the selected recipe, so we do not have to do anything extra at this point.
Like in the recipe source list, the add and subtract buttons are configured
by binding them to the recipe ingredients' NSArrayController objects (the -add: and
-remove: methods, respectively). And with that, the ingredients section is
complete, and we are nearly done with our UI.
7.6
Adding a Splash of Code
Wondering where the code is? As it stands, our recipe application is fully
functional. We can run it without any actual code on our part and start
inputting recipes immediately. The combination of Cocoa and Core Data
makes it possible for us to produce this application with no custom code.
However, we are not stopping there.
Displaying a Picture of the Recipe
Since our iOS counterpart is capable of taking and displaying pictures, it
seems only fair that the desktop variant should be able to add and display
images. Fortunately, from the UI point of view, this functionality is an easy
addition. Drag an NSImageView (aka Image Well) onto our window, and connect
its Value Path setting to the imagePath of the recipe's NSArrayController with a
controller key of selection.
Importing Images
Once we add the NSImageView to our user interface, we need to make our
AppDelegate aware of it. In addition, we need to add a way to set the image path
of our Recipe entities. Therefore, we must update our AppDelegate.h and add an
IBOutlet for the recipe NSArrayController and an IBAction to be able to set the image
path, as shown here:
 
 
Search WWH ::




Custom Search