我已經將數據保存到NSUserDefaults中,但我不知道如何將其顯示到UITable中。如何顯示保存在表中的數據
-(IBAction)savehighscore_button {
int i, ii = -1;
struct high_score {
NSString *name;
int highScore;
};
NSString *nameentered;
nameentered = nametextbox.text;
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 = nameentered;
structArray[i].highScore = myScore;
if (i==ii && i<9)
ii=i+i;
}
else if(i==ii && i<9) {
structArray[i+1].name = nameentered;
structArray[i+1].highScore = myScore;
ii=i+1;
}
}
}
if (ii==-1 && myScore >0) {
structArray[0].name = nameentered;
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]];
}
[userPreferences synchronize];
[nametextbox resignFirstResponder];
[self viewDidLoad];
}