내 NSUserdefaults에 문제가 있습니다. 텍스트 상자에 이름을 입력하고 최고 점수를 클릭하면 응용 프로그램에서 아무런 반응이 없으며 키패드가 화면에 계속 표시됩니다. 데이터를로드하려고하면 name 데이터가 nil이라고 표시됩니다. 내가 가지고있는 점수는 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
그는 깨진 코드 서식을 수정했습니다. – vikingosegundo
이것은 http://stackoverflow.com/questions/4320756/nsuserdefauls-problem/4320827 –