我有一个步进器,在更改其值期间,我需要将值存储在 plist 中。
因此,根据 saveAppPlist 方法,我需要将 NSMutableDictionary 与更改的文件一起传递 - > dictData
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictData format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
if(plistData)
{
[plistData writeToFile:plistPath atomically:YES];
}
这是步进器的方法:
-(void)changeItemQuantityAtRow:(int)row
toValue:(double)value
{
NSMutableDictionary *item = [[items objectAtIndex:row] mutableCopy];
[item setObject:[NSNumber numberWithDouble:value] forKey:@"Quantity"];
[items setObject:item atIndexedSubscript:row];
NSLog(@"%@", items);
NSMutableDictionary *plistDict = [NSDictionary dictionaryWithObjects:items forKeys:[NSArray arrayWithObjects:@"Name", @"Price", @"Quantity", nil]];
NSLog(@"%@", plistDict);
[self saveAppPlist:plistDict];
}
plist 看起来像这样(这只是 4 个项目之一):
<dict>
<key>Items</key>
<array>
<dict>
<key>Name</key>
<string>The zero item</string>
<key>Price</key>
<integer>133</integer>
<key>Quantity</key>
<integer>17</integer>
</dict>
步进器正在更改项目的数量。但是当我尝试更改数量的值时出现这样的错误:
'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:]: count of objects (4) differs from count of keys (3)'
我了解错误的根源,但不知道如何解决此问题。谁能帮我?还有一个 - 每次点击步进器后存储值可能不太好?