2011-04-27 75 views
1

我有,我有以下設置中定義的Settings.bundle一個iPhone應用程序:默認值的PSMultiValueSpecifier

<dict> 
     <key>DefaultValue</key> 
     <integer>2</integer> 
     <key>Key</key> 
     <string>calculationMethod</string> 
     <key>Title</key> 
     <string>CALCULATION_METHOD</string> 
     <key>Titles</key> 
     <array> 
      <string>Method A</string> 
      <string>Method B</string> 
      <string>Method C</string> 
      <string>Method D</string> 
      <string>Method E</string> 
      <string>Method F</string> 
      <string>Method G</string> 
     </array> 
     <key>Type</key> 
     <string>PSMultiValueSpecifier</string> 
     <key>Values</key> 
     <array> 
      <integer>3</integer> 
      <integer>2</integer> 
      <integer>5</integer> 
      <integer>4</integer> 
      <integer>1</integer> 
      <integer>6</integer> 
      <integer>0</integer> 
     </array> 
    </dict> 

正如你可以看到我想要的「方法B」在默認情況下,我定義選擇通過設置DefaultValue。但是,這隻會在列表中選擇「方法B」,但返回的實際值是[settings integerForKey:@「calculationMethod」]爲0,對應於「方法G」。 我在這裏忘記了什麼,或者這不是DefaultValue工作的方式嗎?

PS。在將選擇更改爲其他內容並返回到「方法B」後,我得到正確的值。

回答

2

目前尚不清楚你的意思是[settings integerForKey:@"calculationMethod"]。如果settingsNSUserDefaults的實例,那麼您所看到的確實是預期的行爲。 Settings.bundle中的默認值僅控制在「設置」應用中爲您的應用顯示的內容。在您的應用運行時,它們對NSUserDefaults加載的偏好沒有任何影響。

要獲得與用戶默認值相同的默認值,您將不得不創建第二個plist,其中包含鍵(@"calculationMethod")及其在字典中的默認值。當你的應用程序啓動時,打開這個plist文件並將其傳遞給-[NSUserDefaults registerDefaults:]

+0

謝謝你的回覆Ole。是的,你是對的,'settings'是'NSUserDefaults'的一個實例。你的回答證實了我對'DefaultValue'的作用的懷疑,但說實話我根本沒有得到這種行爲的目的。我的意思是,這裏存在不一致的實際缺陷,因爲您將顯示的值設置爲一個地方,實際值設置爲另一個地方。 – pajevic 2011-04-27 20:18:32

+0

我傾向於同意。您應該向Apple提交錯誤報告/增強請求。 – 2011-04-27 20:21:11