我想通过我的应用程序更改 PSMultiValueSpecifier 标题数组和值数组。这是我的 Root.plist 文件。
<?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>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Login Information</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>Restaurant Code</string>
<key>Key</key>
<string>Restaurant_Code_key</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>Password </string>
<key>Key</key>
<string>Password_key</string>
<key>IsSecure</key>
<true/>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Remember Login Information</string>
<key>Key</key>
<string>Remember_Login_Information_key</string>
<key>DefaultValue</key>
<false/>
<key>TrueValue</key>
<true/>
<key>FalseValue</key>
<false/>
</dict>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Menu Content</string>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Default Language</string>
<key>Key</key>
<string>Default_Language_key</string>
<key>DefaultValue</key>
<integer>0</integer>
<key>Titles</key>
<array>
<string>English</string>
<string>Spanish</string>
</array>
<key>Values</key>
<array>
<integer>0</integer>
<integer>1</integer>
</array>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Update Data on Launch</string>
<key>Key</key>
<string>Update_Data_key</string>
<key>DefaultValue</key>
<false/>
<key>TrueValue</key>
<true/>
<key>FalseValue</key>
<false/>
</dict>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string></string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Reset on Next Launch</string>
<key>Key</key>
<string>Reset_key</string>
<key>DefaultValue</key>
<false/>
<key>TrueValue</key>
<true/>
<key>FalseValue</key>
<false/>
</dict>
</array>
<key>StringsTable</key>
<string></string>
</dict>
</plist>
I tried to change like this Through my application.
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Default Language</string>
<key>Key</key>
<string>Default_Language_key</string>
<key>DefaultValue</key>
<integer>0</integer>
<key>Titles</key>
<array>
<string>English</string>
</array>
<key>Values</key>
<array>
<integer>0</integer>
</array>
</dict>
但这不会改变标题和值。请有人帮助我。下面给出了我使用的代码。
NSURL * settingsURL = [[NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"Settings" withExtension:@"bundle"]]
URLForResource:@"Root" withExtension:@"plist"];
NSMutableDictionary * settingsDict = [NSMutableDictionary dictionaryWithContentsOfURL:settingsURL];
NSMutableArray *settingsArr = [settingsDict objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *loTempDict = [[NSMutableDictionary alloc] init];
loTempDict = [settingsArr objectAtIndex:5];
NSArray *title_Array = [loTempDict objectForKey:@"Titles"];
NSArray *value_Array = [loTempDict objectForKey:@"Values"];
NSArray *lanArray_title = [NSArray arrayWithObject:@"French"];
NSArray *lanArray_value = [NSArray arrayWithObject:@"0"];
[loTempDict setObject:lanArray_title forKey:@"Titles"];
[loTempDict setObject:lanArray_value forKey:@"Values"];
[settingsArr replaceObjectAtIndex:5 withObject:loTempDict];
NSLog(@"final settingsArr ===%@ ",settingsArr);
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
[settingsArr writeToFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"] atomically: TRUE];
谢谢