addHighScore라는 메서드가 있습니다. 사용자가 게임을 종료하기를 원하면 점수를 절약 할 수 있습니다. resources 폴더에서 highScore.plist를 만들고 하나의 항목으로 채 웠습니다. 구조는 다음과 같습니다NSMutableArray/NSMutable 사전이 writeToFile에 데이터를 저장하지 않습니다.
item 1 (array)
Name (dictionary, string)
Level (dictionary, string)
Score(dictionary, Number)
내 문제는 이것이다 : 나는 시뮬레이터에서이 프로그램을 실행할 때, 나는 arrHighScores를 넣은 다음 newScore 사전을 추가 한 후, 모든 것이 잘 보인다 기록은 NSLog를 통해 추가 (그림과 취득 문)하지만 이것은 응용 프로그램이 실행되는 동안에 만 가능합니다. 일단 내가 빠져 나갔다가 다시 들어가면 내가 직접 입력 한 것만 존재합니다.
기기 (iPhone)에서 실행하면 게임 중에도 추가 된 기록이 표시되지 않습니다. 나는 NSDictionary에 관한 모든 예를 살펴 보았고 무엇이 잘못 될지 알 수 없었다.
모든 아이디어 또는 제안 사항을 매우 높이 평가합니다. 모든 도움에 미리 감사드립니다. (지오 ...)
내 방법은 다음과 같습니다
-(IBAction) addHighScore {
NSString *myPath = [[NSBundle mainBundle] pathForResource:@"highScores" ofType:@"plist"];
NSLog(@"myPath: %@", myPath);
NSMutableArray *arrHighScores = [[NSMutableArray alloc] initWithContentsOfFile:myPath];
NSMutableDictionary *newScore = [[NSMutableDictionary alloc] init];
[newScore setValue:@"Geo" forKey:@"Name"];
[newScore setValue:lblLevel.text forKey:@"Level"];
[newScore setValue:[NSNumber numberWithDouble: dblScore] forKey:@"Score"];
[arrHighScores addObject:newScore];
for (int i = 0; i < [arrHighScores count]; i++) {
NSLog(@"Retreiving (%d) --> %@", i, [arrHighScores objectAtIndex:i]);
}
[arrHighScores writeToFile:myPath atomically:YES];
NSMutableArray *tmpArray2 = [[NSMutableArray alloc] initWithContentsOfFile:myPath];
NSSortDescriptor *mySorter = [[NSSortDescriptor alloc] initWithKey:@"Score" ascending:YES];
[tmpArray2 sortUsingDescriptors:[NSArray arrayWithObject:mySorter]];
for (int i = 0; i < [tmpArray2 count]; i++) {
NSLog(@"Retreiving (%d) --> %@", i, [tmpArray2 objectAtIndex:i]);
}
[arrHighScores release];
[tmpArray2 release];
[mySorter release];
[newScore release];
}