Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Programmer

macrumors member
Original poster
Jun 16, 2009
79
0
How can you Save and read information in your application such as a high score.
 
Heres the code

I tried a simple test to see if it worked

Code:
- (void)viewDidLoad {
		     [[NSUserDefaults standardUserDefaults] setObject:@"Name" forKey:@"Text"];
    [super viewDidLoad];
}


- (IBAction)SetTextFieldToSavedText {
	
	NSString *name = [ [NSUserDefaults standardUserDefaults] stringForKey:@"Text"];
	
	names.text = name;
	
}

- (IBAction)PersonEndedTyping {
	
	[[NSUserDefaults standardUserDefaults] setObject:names forKey:@"Text"];

}

The problem is that what it told it ti save isn't saving.
 
Here's your problem:
Code:
[[NSUserDefaults standardUserDefaults] setObject:[B]names[/B] forKey:@"Text"];
names is a UITextField object, not an NSString. What you are doing is setting the UITextField object for that key in NSUserDefaults. What you want to do is set the value of the text property of the UITextField. Like this:
Code:
[[NSUserDefaults standardUserDefaults] setObject:names[B].text[/B] forKey:@"Text"];
 
Thanks So Much!

Thanks a lot. By the way is that app CraigsHarvest your advertising under your comments yours?
 
I Bought

I Bought it i really like your interface and how smoothly it runs
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.