このコードを使用して、コンテンツを 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 のコンテンツの使用に問題があります。だから私の2つの質問は: - 現在のplistの辞書のキーは何ですか? - Tableview のコンテンツを読み取る方法は?