Re: dumb bindings/user defaults question
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