0

いくつかの病院名を保存するプロパティリストを生成しました。次に、そのplistから名前を配列に入れたいと思います。私を助けてください。よろしくお願いします。

4

2 に答える 2

4
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"plist"];
contentArray = [NSArray arrayWithContentsOfFile:plistPath];

これを試して

于 2012-06-27T11:35:38.713 に答える
0

これを試して

NSMutableDictionary* dictionary = [[[NSMutableDictionary alloc] init] autorelease];

NSError *error;
// Look in Documents for an existing plist file
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* metadataPlistPath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat: @"Metadata.plist"]];
[metadataPlistPath retain];

// If it's not there, copy it from the bundle
NSFileManager *fileManger = [NSFileManager defaultManager];
if ( ![fileManger fileExistsAtPath:metadataPlistPath] ) {
NSString *pathToSettingsInBundle = [[NSBundle mainBundle]
pathForResource:@"Metadata" ofType:@"plist"];
[fileManger copyItemAtPath:pathToSettingsInBundle toPath:metadataPlistPath error:&error];
}
//Now read the plist file from Documents
NSString* myPlistPath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat: @"Metadata.plist"] ];

dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:myPlistPath];

return dictionary;
}

//fetch the data based on key
- (NSMutableArray*) fetchMetadataArrayForKey:(NSString*)aKey {
NSMutableArray* arrCategories = [[[NSMutableArray alloc] init] autorelease];
NSMutableDictionary* dictionary = [self fetchMetadata];

arrCategories = [dictionary valueForKey:aKey];

return arrCategories;

}
于 2012-06-27T11:45:50.157 に答える