Setting Up a Multi-View Panel
In this section,
we’re going to change the Preferences panel into a
multi-view panel, so that we can use it to change either the initial
colors or the initial graph parameters (e.g.,
xmin, ymax). Figure 21-8 shows the pop-up menu and two NSViews that
will show up in our new Preferences panel. The particular view that
shows up depends on which tab (Colors or Initial) the user selects.
In the final section of this chapter (and the book!),
we’ll modify GraphView to read its initial graph
conditions out of the defaults database.

Figure 21-8. The two views of the multi-view Preferences dialog
Tab Views
It’s quite easy to set up a tab view with Cocoa: just drag out the tab view and drop your GUI elements into place. Before we do this, however, we need to set up instance variables to hold the additional controls.
Insert the five outlet instance variables shown here in bold into
PrefController.h:#import <Cocoa/Cocoa.h> @interface PrefController : NSObject { // Colors tab IBOutlet id axesColorWell; IBOutlet id graphColorWell; IBOutlet id labelColorWell; // Initial tab IBOutlet id xminCell; IBOutlet id xmaxCell; IBOutlet id xstepCell; IBOutlet id yminCell; IBOutlet id ymaxCell; IBOutlet id window; } ... @endSave
PrefController.h.Open
Preferences.nibin IB.Drag the
PrefController.hicon from PB and drop it in thePreferences.nibwindow in IB.
The last step brought ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access