macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

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

Congratulations!

You now have a fully functional new style preferences window.



There are a few more tips and techniques that you might find useful.

Accessing Preferences "Directly"

In many cases, you will not need to have your PreferencePaneController subclass mediate changes to the preferences values--in these cases, you can add an NSObjectController instance from the palette to the Instances pane of your preference pane's nib file, binding its contentObject to the File's Owner, with Model Key Path "controller."

Your preferences controls can then be bound directly to methods in the underlying controller object (in this example, NPEController).

Adding Help to Your Preferences Panes

In the preference pane's Info.plist file, there is an optional helpAnchor key (you may also remember from part one that we defined some help related methods in NPEPreferencePaneController).

If set, the value for this key should be a help anchor--a reference to a defined page or location in an Apple Help Book.

If you add a help button to your preference pane's custom view, and connect the button action to the showHelp: method of the File's Owner (i.e. the NPEPreferencePaneController subclass), then the help button will open the Application's Apple Help, and jump to the named anchor.

Setting the help anchor will also cause any alerts displayed by showWarningAlert to display a help button, which will direct users to the same help anchor.

Optimizing Code Size

In our example application, NPEPreferencePaneController.m is included in all three targets (the application, and the two preferences panes). This means that object code for this class will be included three times, increasing the size of the final application.

In our example this, is not such a big deal (the binary code for NPEPreferencePaneController is only 25k in size), but in a real-world application, there may be other common code, which can swell the final application size considerably.

You can eliminate this redundancy by creating a new Target, of the type Framework, in your project. All of the common code that is required by two or more preference panes can be added to this new target, and removed from all of the other targets. In the build properties for your new target, you will need to set the Installation Directory setting to @executable_path/../Frameworks.

You should add the new target to the dependencies of your main target, and each preference pane target. You also need to add the target's product (the framework) to the "Link Binaries with Libraries" build phase of the main application target, and to a new Copy Files build phase in the main application target, with a destination of Frameworks.

Final Thoughts

In part one of this article, I showed you how to set up the scaffolding for your new style preferences window. In this part, we covered the actual creation of the preference panes themselves.

Although the initial investment required to support new preference windows is relatively high, Matt Gemmell's SS_PrefsController has already done most of the hard work.

The techniques shown here add a few useful interface tweaks, to make your windows more like Apple's, and reduce the amount of code that you need to write to make use of SS_PrefsController.

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