2013-04-11 2 views
1

문자열 집합과 함께 NSMutableArray를 반환하는 메서드가 있습니다. 이 배열을 (문자열) plist 파일에 추가하고이를 사용하여 UITableView를 채울 수 있습니까? 감사합니다plist에 배열 쓰기 및 tableview 채우기

+1

(http://mattgemmell.com/2008/12/08/what-have-you-tried /) –

+0

NSString * 경로 = [[NSBundle mainBundle] pathForResource : @ "brochurenames"ofType : @ "plist"]; [[self returnBrochureNames] writeToFile : 원자 적으로 : YES]; <성공했지만 읽을 수는 없다. – Daantjeeuh

답변

9

문서 디렉토리에있는 파일 경로를 만들기

NSArray *array = [NSArray arrayWithObjects:@"One", 
        @"Two", 
        @"Three", 
        @"Four", nil]; 

값 배열을 작성, 당신은

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentFolder = [path objectAtIndex:0]; 
NSString *filePath = [documentFolder stringByAppendingFormat:@"myfile.plist"]; 

저장 배열 파일 PLIST하지 않는 응용 프로그램 번들에, 거기에 파일을 쓸 수

[array writeToFile:filePath atomically:YES]; 
NSLog(@"file Stored at %@",filePath); 

plist에서 배열 읽기 다음 코드 사용

NSArray *plistArray = [NSArray arrayWithContentsOfFile:filePath]; 
NSLog(@"%@",plistArray); 

비록 것은 당신은 아직도 당신이 튜토리얼을 참조 할 수 있습니다지고 있지 않은 경우 here [당신이 시도 무엇?]

+1

위대한,이게 정말 도움이되었습니다! 감사! 편집 : 파일 이름 앞에 "/"를 추가하여 실제로 문서 폴더 안에 씁니다. – Daantjeeuh