NSUserDefaultsController keys return nil

I'm trying to implement a preference panel. I have an NSTextField that is bound to the Shared User Defaults Controller . The controller key is values and the Model Key Path is FolderPath .

Every time I try to access that value in code, the string is nil:

NSString *s = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] stringForKey:@"FolderPath"];
NSLog(s);

If I set a default dictionary, the value in the text box displays it properly, but it is still nil when retrieving it again.

    NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"foo"
                                                            forKey:@"FolderPath"];
    [[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:appDefaults];

Am I missing something basic here?


Do you ever send this user defaults controller a -save: message? If not, the values you set probably aren't being saved.

链接地址: http://www.djcxy.com/p/85268.html

上一篇: 如何验证Cocoa中反向变换输入字段的值?

下一篇: NSUserDefaultsController键返回nil