我正在使用此代码将内容添加到 plist 中:
//////////// Save data into plist /////////////////
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"datatesting.plist"];
NSLog(@"path='%@'",path);
NSFileManager *nfm = [[NSFileManager alloc] init];
if([nfm fileExistsAtPath:path])
{
// if file exists, get its contents, add more entries and write back
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSArray *keys = [NSArray arrayWithObjects:@"Title",@"Description",@"Coordinate",nil];
[array addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%@",titlestring],[NSString stringWithFormat:@"%@",descriptionstring],[NSString stringWithFormat:@"%@",coordinadastring], nil] forKeys:keys]];
NSLog(@"modified array=%@",array);
BOOL ok = [array writeToFile:path atomically:YES];
if(!ok){
NSLog(@"Unable to write appended file");
return;
}
} else {
// if file doesn't exist, create a new one
NSMutableArray *array = [[NSMutableArray alloc] init];
NSArray *keys = [NSArray arrayWithObjects:@"Title",@"Description",@"Coordinate",nil];
[array addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%@",titlestring],[NSString stringWithFormat:@"%@",descriptionstring],[NSString stringWithFormat:@"%@",coordinadastring], nil] forKeys:keys]];
NSLog(@"new array=%@",array);
BOOL ok = [array writeToFile:path atomically:YES];
if(!ok){
NSLog(@"Unable to write new file");
return;
}
}
现在我在使用 plist 的内容时遇到了问题。所以我的两个问题是: - 当前 plist 的字典的键是什么?- 在 Tableview 中读取内容的方法是什么?