如果我尝试在我的词典中添加一个新条目(plist),它就不起作用。编辑没问题。我认为问题是,我如何尝试添加条目。
如果我删除以“setObject”开头的行,则返回YES。
我的代码如下:
NSMutableDictionary *updateDict = [[self.plist objectForKey:@"comments"]mutableCopy];
NSMutableDictionary *tmpDict = [[[NSMutableDictionary alloc]init]autorelease];
[tmpDict setObject:comment forKey:@"comment"];
[tmpDict setObject:author forKey:@"author"];
[tmpDict setObject:car forKey:@"car"];
[tmpDict setObject:part forKey:@"part"];
[tmpDict setObject:date forKey:@"date"];
[updateDict setObject:tmpDict forKey:[NSNumber numberWithInt:[updateDict count]+1]];
[self.plist setObject:updateDict forKey:@"comments"];
if([self.plist writeToFile:self.plistPath atomically:YES]) {
return YES;
}
else {
return NO;
}
self.plist是plistPath上文件的本地副本。我的plist的结构看起来像:
我正在为iPad上的iOS 5.0开发。
希望这会有所帮助