iam使用setting.bundle,我尝试使用Switch toggle显示隐藏的图片,这是我的代码,但我想念一下:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[//Some code show the hidden pic]; myPic.hidden = NO;
我的密钥是.e.g = wood_back
我应该使用ObjectForKey
吗?
//声音问题:
现在我尝试关闭我的应用程序的声音效果
播放方法为[myMusic play];
BOOL soundIsOff = [defaults boolForKey:@"sound_off"];
//the problem is here :D
//xcode compiler doesn't copile this code
[myMusic play] = soundIsOff
声音代码:
///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;
答案 0 :(得分:1)
如果是切换切换,您应该使用boolForKey:
返回值。
BOOL wood_back = [defaults boolForKey:@"wood_back"];
// do anything with wood_back, e.g.
myPic.hidden = wood_back;
答案 1 :(得分:0)
[NSUserDefaults standardUserDefaults]值不会自动与Settings.bundle plist文件中定义的值同步。查看我的详细article on how to keep user defaults synched in your app。