Lefora Free Forum
login join
Loading
533 views

setting initial value of popup

Page 1
1–2
regular - member
54 posts

I have a preferences panel that has a popup button that I bound to the Shared User Defaults system. I used the selectedValue and it seems to work, except on the initial launch of the app it is set to nothing. I set up default values on in an init method:

- (id)init
{
    [super init];
    NSMutableDictionary * defaultPrefs = [NSMutableDictionary dictionary];
    [defaultPrefs setObject:@"navDevice" forKey:@"TomTom"];
    prefs = [[NSUserDefaults standardUserDefaults] retain];
    [prefs registerDefaults:defaultPrefs];
    return self;
}


What I want to do now is set the selected item of the popup (navDevicePref) to @"TomTom". Something like:

[navDevicePref ?????:[prefs stringForKey:@"navDevice"]];

 I read through the class description and tried various set... methods and none work in the awake from nib method of my controller.

Todd

?
288 posts

Hi M

Take a look at the code for Aaron Hillegass' book.  You can download it from here:   http://www.bignerdranch.com/solutions/Cocoa-3rd.tgz

in 10_Defaults/RaiseMan_B he has code that works with preferences.  I think you're trying to override a preference and I was able to do that in AppController.m (see below - I've added one line to set the background color to Blue).

If you don't have a copy of his book, I strongly encourage you to purchase it.  When I arrived in Cocoa land as a refugee from MFC and Windows, I was really lost and puzzled by the landscape.  I would have starved to death without that book.

I'm not certain that I've really answered your question, however I'm sure you'll be able to use Aaron's code to get to the bottom of this. 


- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
NSLog(@"applicationShouldOpenUntitledFile:");
[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:[NSColor blueColor]] forKey:BNRTableBgColorKey];

return [[NSUserDefaults standardUserDefaults] boolForKey:BNREmptyDocKey];
}

__________________
Page 1
1–2

Locked Topic


You must be a member to post in this forum

Join Now!