NSUserDefaults and show a picture
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 e开发者_Python百科ffect 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;
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;
[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.
加载中,请稍侯......
精彩评论