我似乎无法在ios用户默认设置中重新编辑此对象。这是我的代码...
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:nil forKey:@"savedScoreCards2"];
在执行此操作之前,我将密钥saveScoreCards设置为一个巨大的3-d字典,现在当我尝试对其进行重写或什至将密钥设置为nil时,我之前设置的那个巨大的3-d字典仍然存在。我似乎无法过度写/替换它(零),或者另一个巨大的3-d字典。有任何想法吗?
更新:
+ (void)saveCurrentScoreCard
{
//save score card
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *savedScoreCards = [[NSMutableDictionary alloc] init];
[userDefaults setObject:nil forKey:@"savedScoreCards2"];//reset at beginning
NSMutableArray *golferOneScoresu = [userDefaults arrayForKey:@"golferOneScoresArray"];
NSMutableArray *golferTwoScoresu = [userDefaults arrayForKey:@"golferTwoScoresArray"];
NSMutableDictionary *golferIconsu = [userDefaults objectForKey:@"golferIconsFirstScene"];
NSMutableArray *golferThreeScoresu = [userDefaults arrayForKey:@"golferThreeScoresArray"];
NSMutableArray *golferFourScoresu = [userDefaults arrayForKey:@"golferFourScoresArray"];
NSMutableDictionary *golferIcons2u = [userDefaults objectForKey:@"golferIcons"];
NSMutableArray *golferNamesu = [userDefaults objectForKey:@"golferNames"];
NSMutableArray *golferNames = [[NSMutableArray alloc] initWithArray:golferNamesu copyItems:YES];
NSMutableDictionary *golferIconsSceneOne = [[NSMutableDictionary alloc]initWithDictionary:golferIconsu];
NSMutableDictionary *golferIcons = [[NSMutableDictionary alloc]initWithDictionary:golferIcons2u];
NSMutableArray *golferFourScores = [[NSMutableArray alloc] initWithArray:golferFourScoresu copyItems:YES];
NSMutableArray *golferThreeScores = [[NSMutableArray alloc] initWithArray:golferThreeScoresu copyItems:YES];
NSMutableArray *golferOneScores = [[NSMutableArray alloc] initWithArray:golferOneScoresu copyItems:YES];
NSMutableArray *golferTwoScores = [[NSMutableArray alloc] initWithArray:golferTwoScoresu copyItems:YES];
NSMutableDictionary *currentScoreCard = [[NSMutableDictionary alloc] init];
[currentScoreCard setObject:golferNames forKey:@"golferNames"];
[currentScoreCard setObject:golferIconsSceneOne forKey:@"golferIconsFirstScene"];
[currentScoreCard setObject:golferIcons forKey:@"golferIcons"];
[currentScoreCard setObject:golferOneScores forKey:@"golferOneScoresArray"];
[currentScoreCard setObject:golferTwoScores forKey:@"golferTwoScoresArray"];
[currentScoreCard setObject:golferThreeScores forKey:@"golferThreeScoresArray"];
[currentScoreCard setObject:golferFourScores forKey:@"golferFourScoresArray"];
[savedScoreCards setObject:currentScoreCard forKey:@"1"];
NSLog([golferIconsSceneOne objectForKey:@"30101"]);
[userDefaults setObject:savedScoreCards forKey:@"savedScoreCards2"];
[userDefaults synchronize];
NSLog(@"SAVED SCORE CARD");
}
最佳答案
如果您只是想删除存储的值,请使用[userDefaults removeObjectForKey:@"savedScoreCards2"]
。
还要调用[userDefaults synchronize];
立即“刷新”您的更改。我认为[userDefaults synchronize]
可能是您所缺少的。
关于iphone - objective-c -覆盖用户默认值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10661447/