Skip navigation.
 
mlRe: dumb bindings/user defaults question
FROM : Matt Neuburg
DATE : Mon Apr 09 18:22:59 2007

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