2012-04-23 56 views
1

我有一個向plist寫入布爾值的問題。 有線的東西是寫入和讀取之前plist的目錄是完全相同的,但我不能寫入它的布爾值。我怎麼解決這個問題? btw:我在iPhone模擬器中獲得了寫入結果,但在真正的iPhone調試中失敗。關於向plist寫boolean文件

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

回答

0

試試這個:

NSLog(@"After update boolValue is %d", [[[tmp objectAtIndex: paramSender.tag] objectForKey: BooleanKey] boolValue]); 
+0

不,結果仍然相同真正的iphone。 – DavidBear 2012-04-23 09:29:21

+0

我想知道爲什麼在模擬器和真正的iPhone – DavidBear 2012-04-23 09:29:54

0

試過這種?

[[ContentList objectAtIndex: paramSender.tag] setBool:YES forKey: BooleanKey]; 
+0

之間的結果是不同的。我不認爲這裏的問題。由於contentlist可以改變對象的布爾值,但不能寫入原始plist ...但是,仍然thx提前~~ – DavidBear 2012-04-23 11:47:10

0

最後,我知道的plist的原則。

包中的plist是隻讀的。如果要以編程方式將數據寫入plist,則必須將plist表格捆綁到文檔目錄,然後無論寫入還是讀取,都可以編輯數據...