我可以动态修改设置包中的 Root.plist 吗?
我的应用程序中有一个设置包..包含 root.plist 现在我有一个屏幕,其中包含一个复选框.. 按下复选框后,我想更改 plist 中 PSToggleSwitchSpecifier 的 DefaultValue 键的 BOOL 值。 由于它是在运行时完成的..我的问题是..文件可以在运行时更改吗?如果是的话..请告诉我如何做到这一点?
这是 plist:
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>DefaultValue</key>
<string></string>
<key>Key</key>
<string>Username</string>
<key>Title</key>
<string>Username</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string></string>
<key>IsSecure</key>
<true/>
<key>Key</key>
<string>Password</string>
<key>Title</key>
<string>Password</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string> <-----toggleSwitch
<key>Title</key>
<string>Remember</string>
<key>Key</key>
<string>CheckBox</string>
<key>DefaultValue</key> <----- Default Value
<false/> <---- want to change this value
</dict>
</array>
<key>Title</key>
<string>Settings</string>
</dict>
</plist>
提前谢谢您;)
I have a settings bundle in my app.. containing root.plist
now i have a screen which contains a checkbox..
on pressing the check box i want to change the BOOL value for DefaultValue key of PSToggleSwitchSpecifier in the plist.
Since its being done at runtime.. my question is that .. can the file be changed at runtime and if yes.. give an idea how to do it??
here is the plist:
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>DefaultValue</key>
<string></string>
<key>Key</key>
<string>Username</string>
<key>Title</key>
<string>Username</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string></string>
<key>IsSecure</key>
<true/>
<key>Key</key>
<string>Password</string>
<key>Title</key>
<string>Password</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string> <-----toggleSwitch
<key>Title</key>
<string>Remember</string>
<key>Key</key>
<string>CheckBox</string>
<key>DefaultValue</key> <----- Default Value
<false/> <---- want to change this value
</dict>
</array>
<key>Title</key>
<string>Settings</string>
</dict>
</plist>
thank you in advance ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于设置包驻留在应用程序包内,因此您无法在运行时更改它,只能在编译时更改。
但是,您可以使用
NSUserDefaults
在运行时设置值,设置应用程序将自动反映这一点。不过,它将保存在其他地方。您可以像处理设置包一样,通过 NSUserDefaults 来读回它。请注意,您不应该直接从设置包中读取,因为它没有意义。您应该始终使用
NSUserDefaults
获取和设置用户默认值。当用户在设置应用程序中进行更改时,NSUserDefaults
将自动反映这一点。他们将始终保持同步。Because the settings bundle resides inside your app's bundle, you cannot change it at runtime, only at compile-time.
You can, however, use
NSUserDefaults
to set the value at runtime, and the settings application will automatically reflect this. It will be saved elsewhere, though. You can just read it back the same way as you would do with the settings bundle, also throughNSUserDefaults
.Note that you shouldn't read from the settings bundle directly, as it makes no sense. You should always fetch and set user defaults using
NSUserDefaults
. When the user makes a change in the settings application,NSUserDefaults
will reflect this automatically. They will always be kept in sync.您无法使用应用程序包修改文件。
You can not modify files with the application bundle..