Iphone 关于将布尔文件写入plist
我有一个关于将布尔值写入plist的问题。 连线的东西是在写入和读取之前plist的dir是完全相同的,但是我不能写入到它的布尔值。我怎样才能解决这个问题? 顺便说一句:我在iPhone模拟器中得到了写入结果,但在真正的iPhone调试中失败了Iphone 关于将布尔文件写入plist,iphone,plist,Iphone,Plist,我有一个关于将布尔值写入plist的问题。 连线的东西是在写入和读取之前plist的dir是完全相同的,但是我不能写入到它的布尔值。我怎样才能解决这个问题? 顺便说一句:我在iPhone模拟器中得到了写入结果,但在真正的iPhone调试中失败了 //--- CODE HERE ---// [ContentList objectAtIndex: paramSender.tag] setValue: [NSNumber numberWithBool: TRUE] forKey: BooleanKey
//--- CODE HERE ---//
[ContentList objectAtIndex: paramSender.tag] setValue: [NSNumber numberWithBool: TRUE] forKey: BooleanKey]; // set object boolean value to be ture;
[ContentList writeToFile: self.plistPath atomically: YES]; // update the plist
NSMutableArray *tmp = [[NSMutableArray alloc] initWithContentsOfFile: self.plistPath]; // get the content from the updated plist
NSLog(@"the bool value is %@", [[ContentList objectAtIndex: paramSender.tag] objectForKey: BooleanKey]);
NSLog(@"After update boolValue is %@", [[tmp objectAtIndex: paramSender.tag] objectForKey: BooleanKey]);
//--- OUTPUT IN NSLOG ---//
2012-04-23 18:09:12.164 iPhoneTips[151:707] the bool value is 1
2012-04-23 18:09:12.167 iPhoneTips[151:707] After update boolValue is 0
//--- FINISH ---//
请尝试以下方法:
NSLog(@"After update boolValue is %d", [[[tmp objectAtIndex: paramSender.tag] objectForKey: BooleanKey] boolValue]);
试过这个吗
[[ContentList objectAtIndex: paramSender.tag] setBool:YES forKey: BooleanKey];
最后,我知道了plist的原理
捆绑包中的plist是只读的。如果您希望以编程方式将数据写入plist,则必须将plist从捆绑包移动到文档目录,然后您可以编辑数据,无论是写入还是读取 不,在真实的iphone中仍然是相同的结果。我想知道为什么模拟器和真实的iphone之间的结果不同。我认为这里没有问题。由于contentlist可以更改对象的布尔值,但不能写入原始plist。。。但是,仍然提前thx~~