开发者

NSUserDefaults and show a picture

开发者 https://www.devze.com 2022-12-25 06:34 出处:网络
iam using setting.bundle and i try to show a hidden picture with Switch toggle , here is my code but i miss something :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号