I woul开发者_高级运维d like to retrieve an Int value from NSUserDefaults, but it always comes up as 0
.
This is how my settings bundle looks:
Type: String: PSMultiValueSpecifier
Title: String: Timer
Key: String: timerValue
DefaultValue: Number: 4
Titles: Array: 5 Number Items 1-5
Values: Array: 5 Number Items 1-5
I use this to access the default...
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger timerValue = [defaults integerForKey:@"timerValue"];
NSLog(@"timerValue is : %i", timerValue);
Always 0
. I have been into Settings and actually changed the value, but still always 0
.
Thanks.
I was experiencing the same problem you describe. It appears the default value is not being set through the bundle. If you change the values through the Settings view and then run your code, you'll probably find it works.
I got around it by setting my default values in the applicationDidFinishLaunching method.
精彩评论