NSUserDefaults默认值返回

NSUserDefaults默认值返回

本文介绍了NSUserDefaults默认值返回(null)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是真的很简单,我缺少,为什么使用下面的代码访问设置的默认值返回(null)

This is probably something really simple that I am missing, why when using the code below to access settings does the default value return as (null)

- (void)updateUIForDistanceUnits {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *test = [userDefaults stringForKey:@"IDDistance"];
    NSLog(@"DISTANCE: %@", test);
}

Root.plist

Root.plist

推荐答案

Root.plist 中的默认值就是UI没有设置值时显示的内容,您必须在代码中执行相同操作在您的应用程序中正确设置 [NSUserDefaults -registerDefaults]

The default value in Root.plist is just what the UI shows if there's no value set, and you have to do the same in your code or set up [NSUserDefaults -registerDefaults] correctly in your application.

您应该会发现, Settings.app NSUserDefaults 将返回正确的值。

You should find that once you set the value in Settings.app NSUserDefaults will return the correct value.

这篇关于NSUserDefaults默认值返回(null)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 02:23