Making the Preferences Panel Work with Defaults

Now that we’ve arranged for the GraphView and ColorGraphView classes to set their initial values from the defaults database, we will modify GraphPaper’s Preferences panel to let the user see those values and change them. We’ll use the same Preferences panel that we created back in Chapter 17, except that we’ll add two new controls — OK and Revert buttons.

The OK button will write the current Preferences panel values into the defaults database. This button will send the okay: action message to the Preferences panel controller object (PrefController).

The Revert button will redisplay the information in the Preferences panel by reading it out of the database. This button will send the revert: action message to PrefController. (Recall that we added the okay: and revert: action methods in IB and unparsed them into PrefController class files back in Chapter 17).

We’ll also modify the PrefController class so that the code for setting up the initial value of each color well is moved from the awakeFromNib method to the revert: method. This way, we won’t have to duplicate the same code in two different methods.

Modifying the Preferences Panel

  1. Open GraphPaper’s auxiliary nib file, Preferences.nib, in IB (double-click it in PB).

  2. Make the Preferences panel big enough to add Revert and OK buttons, as shown in Figure 21-5.

The Preferences panel with Revert and OK buttons

Figure 21-5. The Preferences ...

Get Building Cocoa Applications: A Step by Step Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.