1

ブール値を plist に書き込むことについて質問があります。有線のものは、書き込み前のplistのディレクトリと読み取りはまったく同じですが、ブール値に書き込むことはできません。どうすればこの問題を解決できますか? ところで: iPhone シミュレーターでは書き込み結果が得られましたが、実際の iPhone デバッグでは失敗しました。

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

3 に答える 3

0

最後に、私はplistの原理を知っています。

バンドル内のplistは読み取り専用です。プログラムでplistにデータを書き込みたい場合は、バンドルからplistをドキュメントディレクトリに移動する必要があります。そうすれば、書き込みや読み取りに関係なくデータを編集できます...

于 2012-04-24T03:41:50.550 に答える
0

これを試しましたか?

[[ContentList objectAtIndex: paramSender.tag] setBool:YES forKey: BooleanKey];
于 2012-04-23T09:52:33.203 に答える
0

代わりにこれを試してください:

NSLog(@"After update boolValue is %d", [[[tmp objectAtIndex: paramSender.tag] objectForKey: BooleanKey] boolValue]);
于 2012-04-23T09:23:31.687 に答える