Skip navigation.
 
mlRe: dumb bindings/user defaults question
FROM : Andrew Kinnie
DATE : Mon Apr 09 19:19:48 2007

Hmmm.  I knew Aaron Hillegass's book has you do it in a separate nib, unfortunately, both my copies are in storage from my recent move, so I followed the directions in Apple's "Binding Your Preferences in Cocoa" tutorial instead, which suggests putting the preferences panel in MainMenu.nib of a document based app.  That does make sense that it is timing though. 

I will give this a try later, when I have my mac in front of me.  Would it be better if I added a panel to my myDocument.nib?

Thanks.

Andrew


On Monday, April 09, 2007, at 12:23PM, "Matt Neuburg" <<email_removed>> wrote:
>On Sun, 8 Apr 2007 15:06:14 -0400, "Andrew R. Kinnie" <<email_removed>>
>said:

>>I decided it was better to put this on a separate preferences panel.
>>I created a panel in the MainMenu.nib and placed the text field bound
>>the same way on that panel (SharedUserDefaults -> values.myKey)  The
>>panel is bound to the Preferences menu item (makeKeyAndOrderFront).
>>
>>However, the initial values do not appear when the preference panel
>>is loaded.

>
>The problem is one of timing. MainMenu.nib is loaded when your application
>starts up, so your defaults are being initialized too late. There are two
>easy solutions:
>
>(1) Put the preferences panel in a separate nib, which won't be loaded until
>after your application has finished launching. Or,
>
>(2) Perform your defaults initialization earlier. For example, you can do it
>in main, like this:
>
>int main(int argc, char *argv[])
>{
>    // initialize defaults before loading a nib that uses them
>    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
>    [[NSUserDefaults standardUserDefaults] registerDefaults:
>        [NSDictionary dictionaryWithObjectsAndKeys:
>            ...., // real values go here
>            nil]];
>    [pool release];
>    // and away we go
>    return NSApplicationMain(argc,  (const char **) argv);
>}
>
>m.
>
>--
>matt neuburg, phd = <email_removed>, <http://www.tidbits.com/matt/>
>A fool + a tool + an autorelease pool = cool!
>AppleScript: the Definitive Guide - Second Edition!
><http://www.amazon.com/gp/product/0596102119>
>
>
>
>
>

Related mailsAuthorDate
mldumb bindings/user defaults question Andrew R. Kinnie Apr 8, 21:06
mlRe: dumb bindings/user defaults question Matt Neuburg Apr 9, 18:22
mlRe: dumb bindings/user defaults question Andrew Kinnie Apr 9, 19:19