开发者

NSUserDefaultsController keys return nil

开发者 https://www.devze.com 2023-03-29 03:11 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消