问题
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
回答1:
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.
You should find that once you set the value in Settings.app NSUserDefaults will return the correct value.
来源:https://stackoverflow.com/questions/10706685/nsuserdefaults-default-value-returning-null