Quote:
Originally Posted by kohjingyu
Code:
- (void)viewDidLoad
{
//Load data here
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"high_score"]) {
high_level_value=[[NSUserDefaults standardUserDefaults] integerForKey:@"high_score"];
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
[super viewDidLoad];
}
- (void)applicationWillTerminate:(NSNotification *)notification
{
//Save data here
[[NSUserDefaults standardUserDefaults] setInteger:high_level_value forKey:@"high_score"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
There are a few errors in your code here.
Firstly, your if statement doesn't compare an integer to another integer.
Try this:
Code:
- (void)viewDidLoad
{
//Load data here
high_level_value=[[NSUserDefaults standardUserDefaults] integerForKey:@"high_score"];
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
[super viewDidLoad];
}
Hope that helps. 
|
Just tried that and got nothing, no errors, or crashes, just not loading in the high level when i restart. Just a question, this should work in the sim right, its not something that must be on the device?