tags:

views:

25

answers:

2

Hi , iam using setting.bundle and i try to show a hidden picture with Switch toggle , here is my code but i miss something :

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[//Some code show the hidden pic];   myPic.hidden = NO;

my key is .e.g = wood_back should i use ObjectForKey ?

//Sound Problem :

now i try to off a sound effect on my app

play method is [myMusic play];

BOOL soundIsOff = [defaults boolForKey:@"sound_off"];
//the problem is here :D
//xcode compiler doesn't copile this code 

[myMusic play] = soundIsOff

sound code :

///sound effect
    NSString * musicSonati = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
    myMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicSonati] error:NULL];
    myMusic.delegate = self;
    myMusic.numberOfLoops = 0;
+1  A: 

If it's a switch toggle you should get the value back using boolForKey:.

BOOL wood_back = [defaults boolForKey:@"wood_back"];
// do anything with wood_back, e.g.
myPic.hidden = wood_back;
KennyTM
thank you Kenny . Works great :):-* :-Xhave you any tutorial with Slider toggle ? :D
Momeks
@Momeks: `doubleForKey:`.
KennyTM
kenny i have another problem ! check the question again !
Momeks
@Momeks: Meh, ask a new question!
KennyTM
here :http://stackoverflow.com/questions/2554905/off-a-sound-effect-with-nsuserdefaults
Momeks
A: 

[NSUserDefaults standardUserDefaults] values are not automatically synchronized with the values defined in your Settings.bundle plist files. Check out my detailed article on how to keep user defaults synched in your app.

Zack