我遇到NSUserdefaults问题。当我在文本框中输入名称并单击高分时,应用程序将不会响应任何内容,并且键盘仍将保留在屏幕上。当我试图加载数据时,它说名称的数据是零。我的得分是90.有人可以告诉我我的编码有什么问题。数据不保存在NSUserDefaults中
非常感谢。
-(IBAction)savehighscore_button {
int i, ii = -1;
struct high_score {
NSString *name;
int highScore;
};
struct high_score structArray[10];
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
for (i=0; i<10; i++) {
if ([userPreferences stringForKey :[NSString stringWithFormat:@"highScoreNameEntry%d",i]]!=nil && [userPreferences stringForKey :[NSString stringWithFormat:@"highScoreEntry%d"]]!=nil) {
structArray[i].name= [userPreferences stringForKey:[NSString stringWithFormat:@"highScoreNameEntry%d",i]];
structArray[i].highScore = [userPreferences integerForKey:[NSString stringWithFormat:@"highScoreEntry%d",i]];
ii = i;
}
}
if (myScore >0) {
for (i==ii; i>=0; i--) {
if (myScore > structArray[i].highScore) {
if (i<9) {
structArray[i+1] = structArray[i];
structArray[i].name = nametextbox.text;
structArray[i].highScore = myScore;
if (i==ii && i<9) {
structArray[i+1].name = nametextbox.text;
structArray[i+1].highScore = myScore;
ii=i+i;
}
else if(i==ii && i<9) {
structArray[i+1].name = nametextbox.text;
structArray[i+1].highScore = myScore;
ii=i+1;
}
}
}
if (ii==-1 && myScore >0) {
structArray[0].name = nametextbox.text;
structArray[0].highScore = myScore;
ii=0;
}
for (i=0; i<=ii; i++) {
[userPreferences setObject:structArray[i].name forKey:[NSString stringWithFormat:@"highScoreNameEntry%d",i]];
[userPreferences setInteger:structArray[i].highScore forKey:[NSString stringWithFormat:@"highScoreEntry%d",i]];
}
}
}
}
喜卡尔,可我知道ü编辑哪个部分。 – lol 2010-12-01 18:25:28
他修复了你破碎的代码格式 – vikingosegundo 2010-12-01 18:28:08