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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-05-2009, 07:26 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
Default NSUserDefaults troubles

Eventually, I want to use NSUser defaults to store some high score type stuff... but as a test, i'm just using it to store a slider value... here's what I've got...



-(IBAction)slidervaluechanged{
mySlider.value = DefaultValue;
}

- (void)writeSettingNSString*)setting forKeyNSString*)theslidervalue;
{
NSUserDefaults* defaults = [ NSUserDefaults standardUserDefaults ];
[ defaults setObject:mySlider forKey:theslidervalue ];
}

- (NSString*)settingForKeyNSString*)theslidervalue
{
DefaultValue = [ [ NSUserDefaults standardUserDefaults ] objectForKey: theslidervalue ];

}


I'm not sure if I'm doing this right, much less if I'm doing it wrong... Any help would be much appreciated. Thanks
starwarsdevwookie59 is offline   Reply With Quote
Old 07-06-2009, 12:13 AM   #2 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Default

Quote:
Originally Posted by starwarsdevwookie59 View Post
Eventually, I want to use NSUser defaults to store some high score type stuff... but as a test, i'm just using it to store a slider value... here's what I've got...
The following works for me. I use it to save the state of a switch that determines if background music plays. Hopefully this will help you.

Code:
//Saving the sound default
-(void)saveSoundUserDefaults:(NSString*)soundString {
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	NSLog(@"Saving the sound defaults");
	if (standardUserDefaults) {
		[standardUserDefaults setObject:soundString forKey:@"audioSwitch"];
		[standardUserDefaults synchronize];
	}
}

//Retrieve what I need
-(NSString*)retrieveFromUserDefaults {
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	NSString *val = [standardUserDefaults objectForKey:@"audioSwitch"];
	return val;
}
DenVog is offline   Reply With Quote
Reply

Bookmarks

Tags
nsinteger, nsuserdefaults, nsuserdfault, saving, slider

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 244
13 members and 231 guests
2WeeksToGo, AdamL, ADY, BrianSlick, Dani77, Dattee, headkaze, mer10, mgon987, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,745
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0