如何在最后一次操作中保存用户数据?

时间:2014-04-22 10:58:23

标签: ios objective-c

我需要在游戏中隐藏视图,但仅限于最后一级

代码:

-(IBAction)btContinueClick:(id)sender
{
    if(nCurrentLevel == [first_wordlist count])
    {

        UIAlertView *info = [[UIAlertView alloc]initWithTitle:@"Well done" message:@"You've completed this game!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [info show]; //// Change Game End Message

        [self dismissViewControllerAnimated:TRUE completion:nil];
        [savedStock setObject:[NSNumber numberWithFloat:[first_wordlist count]-1] forKey:@"currentlevel"];
        [savedStock writeToFile: path atomically:YES];
    }
} 

如果我不保存(隐藏的匹配视图)他的数据,他们将能够制作越来越多的硬币到无限!

额外变量:

NSMutableArray *firstword;
NSMutableArray *firstjumbledword;
NSMutableArray *first_1st_WordCount;

int nCurrentWord;

IBOutlet UIView *MatchView;

NSMutableArray *firstMatchedWord;
NSMutableArray *firstWordToMatch;
NSMutableArray *firstImageHidden;

NSString *stringResult;

int nCurrentLevel;
int nCurrentLevelPoint;

1 个答案:

答案 0 :(得分:0)

正如其他人所建议的那样,您始终可以使用NSUserDefaults在本地保存您的关卡数据。

写一个整数:

[[NSUserDefaults standardUserDefaults] setInteger:2456 forKey:@"Score Level 1"];

从NSUserDefaults读取值:

  NSInteger savedScore= [[NSUserDefaults standardUserDefaults]integerForKey:@"Score Level 1"];