Re: dumb bindings/user defaults question
Re: dumb bindings/user defaults question
- Subject: Re: dumb bindings/user defaults question
- From: Andrew Kinnie <email@hidden>
- Date: Mon, 09 Apr 2007 10:19:48 -0700
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@hidden> wrote:
>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