oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Adding a New Style Preferences Window to Your App, Part 1
Pages: 1, 2, 3, 4

Adding the Preferences Controller to the Application

To add NPEPrefsController to our application, we will add a single variable and method to our NPEController class.

The variable _prefsController is a pointer to an NPEPrefsController object (so we also need to import NPEPrefsController.h). The method, showPrefs, is listed below:

- (IBAction) showPreferences:(id) sender{
    if(! _prefsController){
        NSString *path = nil;
        NSString *ext = nil;
        _prefsController = [[NPEPrefsController alloc] initWithPanesSearchPath:path 

        // so that we always see the toolbar, even with just one pane
        [_prefsController setAlwaysShowsToolbar:YES];
        [_prefsController setPanesOrder:[NSArray arrayWithObjects:@"General", @"Advanced", nil]];

    [_prefsController showPreferencesWindow];

Oops. One more thing. We need to add the line [_prefsController release]; to NPEController's dealloc method.

Finally, opening MainMenu.nib in Interface Builder, we re-read the NPEController.h file (make sure you declare showPreferences in the header), and connect the Preferences menu item to the showPreferences action in NPEPrefsController.

Running the Application

Build and run the NewPreferencesExample application in XCode. If everything goes to plan, a window will appear onscreen.

Select the "Preferences..." item from the NewApplication menu (you can rename this in Interface Builder if you like), and, as if by magic, a dialog box will appear:

"Preferences are not available for NewPreferencesExample"


Figure 2. The NewPreferencesExample application, with no preferences.

All of the scaffolding for our new preferences window is now in place. In part two of this article, I will cover the actual creation of the preference panes.

Martin Redington is a long-time Mac user who recently started writing Mac shareware. His first product, MySync, provides Mac-to-Mac syncing without .Mac and is currently in public beta.

Return to the Mac DevCenter