2010-03-30 49 views
0

IAM使用setting.bundle和我嘗試以顯示與開關撥動隱藏圖像,這裏是我的代碼,但我錯過了什麼:和NSUserDefaults的出現畫面

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

我的關鍵是.eg = 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; 

回答

1

如果這是一個開關切換,你應該使用boolForKey:得到值。

BOOL wood_back = [defaults boolForKey:@"wood_back"]; 
// do anything with wood_back, e.g. 
myPic.hidden = wood_back; 
+0

謝謝你肯尼。很好用:): - *:-X 你有任何使用Slider切換的教程嗎? :D – Momi 2010-03-30 14:29:02

+1

@Momeks:'doubleForKey:'。 – kennytm 2010-03-30 14:34:15

+0

肯尼我有另一個問題!再次檢查問題! – Momi 2010-03-31 14:17:46