Learn Objective-C on the Mac - Mark Dalrymple [75]
In the Library, search for “numberformatter,” and drag the resulting NSNumberFormatter (a subclass of NSFormatter) to the small label, which highlights when you’re right on top of it. Then select the formatter by first selecting the small label in the window, then clicking on the tiny icon that appears below it. That icon represents the formatter, which is attached to the control, and clicking on it lets you edit the formatter’s attributes. Now bring up the Attributes Inspector, and see what the options for NSNumberFormatter look like. You get a whole host of options for defining how the formatter will display numbers, including how many digits to display after a decimal point, what the decimal and thousands separators look like, currency symbols, and so on. You don’t actually need to configure anything in there right now, since the default values for an NSNumberFormatter are just right for our purposes: By default, NSNumberFormatter will round any value to the nearest integer.
Now select both the slider and the small label and duplicate them twice, once for divinity and once for goodness, placing the new sets in line with the labels. Figure 7-10 shows what you should be seeing at this point.
Figure 7-10. Replacing text fields with sliders
Now for the final step: binding the new controls to the selected MythicalPerson’s values. One at a time, select each of these six objects (three sliders and three labels), and bind its Value so that the Mythical Person Array Controller is the controller, selection is the Controller Key, and the appropriate attribute—power, divinity, or goodness—is selected in the Model Key Path combo box.
Save your work, switch to Xcode, and click the Build & Run button. Running the app, you should see the sliders and text fields update as you select objects in the table, and dragging a slider should update both the corresponding text field and the matching cell in the table view. If you play around with the app a bit more, trying out the search field above the table view, you may be in for a rude awakening, and find that your app hangs or crashes, and dumps a lot of strange output into the console log in Xcode. The problem lies with the search field that the assistant creates: it’s automatically bound up with several search predicates, one for each attribute. These search predicates (which you’ll be seeing more of in Chapter 9) are used to try to match up the value that the user types in with objects in the data store. The assistant-created GUI includes a search predicate for every attribute, including the binary depiction attribute. Unfortunately, binary and transformable attribute are inherently not searchable, and Core Data tries to deal with the mess up as well as it can, but unfortunately it doesn’t help. The search functionality is inoperable with a search predicate for the depiction attribute in place.
Fortunately, you can make searching work for your project by removing the offending search predicate. Use the Bindings Inspector to examine the search field’s bindings. In the “Search” category, you’ll see a bunch of numbered Predicate bindings. Open each one until you find the one for “depiction,” then just deactivate that binding. Unfortunately, even though we wrote that paragraph as if it what we described actually works, it doesn’t quite work if you’re running Leopard. Turning off the checkbox