Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 10-11-2009, 09:07 AM   #7 (permalink)
jbullfrog
Registered Member
 
Join Date: Jun 2009
Posts: 140
jbullfrog is on a distinguished road
Default

Quote:
Originally Posted by kohjingyu View Post
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?
jbullfrog is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,282
Threads: 93,959
Posts: 402,306
Top Poster: BrianSlick (7,971)
Welcome to our newest member, kurtwatson
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.