0
일부 병원 이름을 저장하는 속성 목록을 생성했습니다. 이제 그 이름을 plist에서 배열로 가져 오려고합니다. 도와주세요. 고맙습니다.프로그래밍 방식으로 속성 목록에서 NSArray로 데이터를 가져 오는 방법은 무엇입니까?
일부 병원 이름을 저장하는 속성 목록을 생성했습니다. 이제 그 이름을 plist에서 배열로 가져 오려고합니다. 도와주세요. 고맙습니다.프로그래밍 방식으로 속성 목록에서 NSArray로 데이터를 가져 오는 방법은 무엇입니까?
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"plist"];
contentArray = [NSArray arrayWithContentsOfFile:plistPath];
이
당신은 아마 당신이 대답의 왼쪽에 눈금을 클릭하여 정답을 얻는 경우에 대답을 수락해야이
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;
}
을 시도하려고 – Sumanth
AssamHospitals = [[NSArray를 alloc] initWithContentsOfFile : [[NSBundle mainBundle] \t \t \t \t \t \t \t \t \t \t \t pathForResource : @ "HospitalListAssam"of Type : @ "plist"]]]; – rimpi
귀하의 질문은 무엇입니까? – Sumanth