2013-11-27 3 views
0

.plist 파일이 있습니다. plist에 데이터를 쓸 때 추가하지 않지만 이전 내용을 덮어 씁니다. 여기 plist에 데이터를 추가하는 방법은 무엇입니까?

내 코드는

, 그것은 이전에 추가됩니다하고 덮어 쓰지 않도록 PLIST에 데이터를 기록하는 방법
// get paths from root direcory 
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); 
// get documents path 
NSString *documentsPath = [paths objectAtIndex:0]; 
// get the path to our Data/plist file 
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"HistoryList.plist"]; 

// set the variables to the values in the text fields 
NSString *str=[NSString stringWithFormat:@" %@ %@ %@",strname.text,strnum.text,selectfield.text]; 
self.historyArray = str; 

// create dictionary with values in UITextFields 
NSDictionary *plistDict = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: historyArray, nil] forKeys:[NSArray arrayWithObjects: @"Name", nil]]; 

NSString *error = nil; 
// create NSData from dictionary 
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error]; 

// check is plistData exists 
if(plistData) 
{ 
    // write plistData to our Data.plist file 
    [plistData writeToFile:plistPath atomically:YES]; 
} 
else 
{ 
    NSLog(@"Error in saveData: %@", error); 

} 

?

+0

http://stackoverflow.com/questions 새 항목 사전을 수정 사전

  • 로 .plist 파일 및로드 읽기/8884215/appending-data-to-plist-iphone – the1pawan

  • +0

    @Bhumeshwerkatre 그래서 그냥 코멘트를하기보다는 질문을 닫으십시오. – trojanfoe

    +0

    @ user3040536 http://ipgames.wordpress.com/tutorials/writeread-data-to-plist-file/ 위의 링크를 확인하면 도움이 될 수 있습니다. –

    답변

    0
    1. 전체 사전이 이전 파일을 대체하는 저장
    +0

    하지만 어떻게 할 수 있습니까 ?? – user3040536

    +0

    NSDictionary * dict = [NSDictionary dictionaryWithContentsOfFile : plistPath]; – Traze

    관련 문제