PSMultiValueSpecifier的DefaultValue [英] DefaultValue for PSMultiValueSpecifier

查看:143
本文介绍了PSMultiValueSpecifier的DefaultValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,其中定义了具有以下设置的Settings.bundle:

I have an iPhone app where I have defined an Settings.bundle with the following settings:

<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>

如您所见,我希望通过设置DefaultValue来默认选择方法B".但是,这仅选择列表中的方法B",但返回的实际值是通过[设置integerForKey:@"calculationMethod"]设置的,为0,它对应于方法G". 我在这里忘记了什么吗?还是这不是DefaultValue的工作方式?

As you can see I want the "Method B" to be selected by default which I define by setting the DefaultValue. However, this only selects the "Method B" in the list, but the actual value returned is by [settings integerForKey:@"calculationMethod"] is 0, which corresponds to "Method G". Am I forgetting something here or is this not the way DefaultValue works at all?

PS.在将选择内容更改为其他内容然后返回到方法B"之后,我得到了正确的值.

PS. After I change the selection to something else and then back to "Method B" I get the correct value.

推荐答案

目前尚不清楚[settings integerForKey:@"calculationMethod"]是什么意思.如果settingsNSUserDefaults的实例,则您所看到的确实是预期的行为. Settings.bundle中的默认值仅控制在设置"应用程序中为您的应用程序显示的内容.它们对您在应用运行时从NSUserDefaults加载的首选项完全没有影响.

It's not clear what you mean by [settings integerForKey:@"calculationMethod"]. If settings is an instance of NSUserDefaults, what you are seeing is indeed the expected behavior. The default values in the Settings.bundle only control what is displayed for your app in the Settings app. They have no influence at all on the preferences you load from NSUserDefaults while your app is running.

要将相同的默认值转换为用户默认值,您将必须创建第二个plist,该plist在字典中包含键(@"calculationMethod")及其默认值.应用启动时,打开此plist文件并将其传递给-[NSUserDefaults registerDefaults:].

To get the same default values into the user defaults, you will have to create a second plist that contains the keys (@"calculationMethod") and their default values in a dictionary. When your app launches, open this plist file and pass it to -[NSUserDefaults registerDefaults:].

这篇关于PSMultiValueSpecifier的DefaultValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆