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; } ... @end
Save
PrefController.h
.Open
Preferences.nib
in IB.Drag the
PrefController.h
icon from PB and drop it in thePreferences.nib
window in IB.
The last step brought ...
Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.