在目标C中设置Bundle时,NSDictionary为null

时间:2014-01-16 19:41:48

标签: ios iphone objective-c settings.bundle

我在设置中有textFields,我可以从中获取值。每当我尝试从PSMultiValueSpecifier获取字典时,它始终为null。即使我在设置包中进行选择仍然为空,我可以理解它的null util用户进行选择,但它始终保持为空。

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-               1.0.dtd">
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
    <dict>
        <key>Title</key>
        <string>Please Select Orientation</string>
        <key>Type</key>
        <string>PSGroupSpecifier</string>
    </dict>
    <dict>
        <key>Type</key>
        <string>PSToggleSwitchSpecifier</string>
        <key>Title</key>
        <string>Landscape</string>
        <key>Key</key>
        <string>orientationSwitch</string>
        <key>DefaultValue</key>
        <true/>
    </dict>
    <dict>
        <key>Type</key>
        <string>PSGroupSpecifier</string>
        <key>Title</key>
        <string>Select Board</string>
    </dict>
    <dict>
        <key>Type</key>
        <string>PSTextFieldSpecifier</string>
        <key>Title</key>
        <string></string>
        <key>Key</key>
        <string>boardTextField</string>
    </dict>
    <dict>
        <key>Type</key>
        <string>PSMultiValueSpecifier</string>
        <key>Title</key>
        <string>Select Board</string>
        <key>Key</key>
        <string>boardChoice</string>
        <key>DefaultValue</key>
        <string>1</string>
        <key>Titles</key>
        <array>
            <string>Glass</string>
            <string>Welcome</string>
            <string>Mate</string>
        </array>
        <key>Values</key>
        <array>
            <string>0</string>
            <string>1</string>
            <string>2</string>
        </array>
    </dict>
</array>
<key>StringsTable</key>
<string>Root</string>
 </dict>
 </plist>

以下是我获得价值的方式。

 NSDictionary *boardChoice = [defaults dictionaryForKey:@"boardChoice"];
 NSLog(@"board Choice = %@", boardChoice);

由于

1 个答案:

答案 0 :(得分:2)

“PSMultiValueSpecifier”类型的首选项不会在中设置字典 用户默认值,但可能是“值”之一。所以

NSString *boardChoice = [defaults stringForKey:@"boardChoice"];

应该有效,在你的情况下应该返回“0”,“1”或“2”。