开发者

saving data in iPhone development

I have some unsolved problem right now. My game is done, now I am at the last stage. In the main menu of the game there will be a button called goodies. Only appears when the user win the game once. I can do until that part . But the last part is to save that goodies. Meaning when the player exist the game after he able to make the button appear, the button still there when he gets back to the game? Could you guys help me out I am not quite sure how to do it. I heard a lot 开发者_运维问答about NSUSerDefault, but don know how it works and how to apply it properly. Thanks for any help.

DegrafeurAppDelegate *appdelegate = (DegrafeurAppDelegate *) [[UIApplication sharedApplication] delegate];

    //BOOL b = appdelegate.checkStatus;

    if(appdelegate.checkStatus == YES)
    {
        [goodies setVisible:YES];
    }
    else
    {
        [goodies setVisible:NO];
    }

This is my code to enable the button after winning once. But how to save it, please help me


As you mentioned, you can user NSUserDefaults:

NSUserDefaults myPrefs = [[NSUserDefaults alloc] init];
[myPrefs setBool:YES forKey:@"displayed_win_button"];
[myPrefs release];

and later to check the value:

if([myPrefs boolForKey:@"displayed_win_button"]) { ... }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜