2011-02-03 5 views
1

응용 프로그램에서 plist :아이폰에 plist 배열 개체를 작성하는 방법?

root ---> dictionary 
    cell ----> array 
    item0 ---> string 
    item1 ----> string 

등등.

plist &에서 데이터를 보유하는 tableView에서 tableview navigation baradd button를 보유합니다. 내가 그것을 클릭하면 text field & button을 보유하는 다른 뷰를 푸시합니다. 단추를 클릭하여 마지막 개체의 배열에있는 텍스트 필드의 텍스트를 plist에 저장하려고합니다.

테이블 뷰를 다시로드 할 때마다 데이터는 plist에 영구 저장됩니다.

답변

3

이 코드는 ....이 도움이

-(void)dataFetching 
{ 
NSMutableDictionary *categoryList = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Give the file path"]; 
NSMutableArray *array =(NSMutableArray *) [categoryList valueForKey:@"write the array name here"]; 

/* hope u know how a table loads data from the array */ 

/*whenever add button is pressed on the table view cell, view would be shown with a textfield and a button, isn't it? */ 

/* by setting the delegate for textfield, using the textfieldDidEnterEditing: method capture the text from the textfield*/ 
// for example, 
NSString *testStr = @"test String"; //[textfield text]; 
//Now, 

int lastItemIndex = [array count]; 
[array insertObject:testStr atIndex:lastItemIndex]; 
// and whenever you want you can save it on to the file like this 

[categoryList writeToFile:@"Give the file path" atomically:YES]; 

[categoryList release]; 
} 

희망. ....

+0

이 게시물을 다시 열면 scratch me, 파일에서 mustabledictionary를로드하고 파일을 업데이트하고 파일에 다시 쓰는 방법을 알고 싶습니다. :) – JackTurky

1

확인 방법있는 NSDictionary과 NSArray를

에 대한

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag 

도 여기

+ (id)arrayWithContentsOfFile:(NSString *)aPath 
+ (id)dictionaryWithContentsOfFile:(NSString *)path 
관련 문제