• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: dumb bindings/user defaults question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dumb bindings/user defaults question


  • Subject: Re: dumb bindings/user defaults question
  • From: Matt Neuburg <email@hidden>
  • Date: Mon, 09 Apr 2007 09:22:59 -0700
  • Thread-topic: dumb bindings/user defaults question

On Sun, 8 Apr 2007 15:06:14 -0400, "Andrew R. Kinnie" <email@hidden>
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@hidden, <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>



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: problem with interaction between NSTableView and fieldEditor
  • Next by Date: Re: How to make NSWindow redraw vacated rects "ifNeeded"?
  • Previous by thread: dumb bindings/user defaults question
  • Next by thread: Re: dumb bindings/user defaults question
  • Index(es):
    • Date
    • Thread