首次启动应用程序时,我在从设置包中检索默认值时遇到问题。所有非多值字段都正确返回默认值。所有多值字段都返回 NULL。我用来检索当前值的代码:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *upt=[defaults objectForKey:@"upthreshold"];
Root.plist 的相关部分是:
<dict>
<key>Title</key>
<string>Update Threshold</string>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Key</key>
<string>upthreshold</string>
<key>DefaultValue</key>
<string>15</string>
<key>Titles</key>
<array>
<string>2 km</string>
<string>5 km</string>
<string>10 km</string>
<string>15 km</string>
<string>25 km</string>
<string>50 km</string>
<string>75 km</string>
<string>100 km</string>
<string>150 km</string>
<string>250 km</string>
<string>500 km</string>
<string>1000 km</string>
</array>
<key>Values</key>
<array>
<string>2</string>
<string>5</string>
<string>10</string>
<string>15</string>
<string>25</string>
<string>50</string>
<string>75</string>
<string>100</string>
<string>150</string>
<string>250</string>
<string>500</string>
<string>1000</string>
</array>
</dict>
我希望“15”会作为当前值返回,因为它被设置为默认值。多值字段是否需要一些不同的处理?正如我之前所说,在此之前有 6 个字段可以正确返回它们的值。此字段和以下 2 个多值字段没有。多值字段的定义都相同。