Ok, one small step for my app, one big step for me!
After thinking some more I solved my issue! I wasnt declaring the NSUserDefaults in the .h, so I set this in the ViewController.h
Code:
NSUserDefaults *prefs;
@property (nonatomic, retain) NSUserDefaults *prefs;
and in the ViewController.m
Code:
- (void)viewDidLoad {
self.prefs = [NSUserDefaults standardUserDefaults];
// Check to see what was stored in the user prefs, and update the label with that colour.
if ([prefs stringForKey:@"high_score"]) {
NSLog(@"The prefs is set.");
high_level.text = [prefs stringForKey:@"high_score"];
}
high_level_value=[[NSUserDefaults standardUserDefaults] integerForKey:@"high_score"];
NSLog(@"set high level");
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];
NSLog(@"check close high level");
[super viewDidLoad];
}
- (void)applicationWillTerminate:(NSNotification *)notification
{
//Save data here
[[NSUserDefaults standardUserDefaults] setInteger:[high_level.text intValue] forKey:@"high_score"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"app quit, save high level");
}
Thanks for all the help