2011-10-27 2 views
0

NSArray에 NSString을 추가하고 완벽하게 작동하는 다른 Tableview에서 다시 읽는 중입니다. 내 FavTableView에서.plpl에 NSArray 추가

NSString *documentDirectory = [self applicationDocumentsDirectory]; 
    NSString *path = [documentDirectory stringByAppendingPathComponent:@"Favs.plist"]; 

    NSArray *Array = [[NSArray alloc] initWithObjects:self.title, nil]; 

    [Array writeToFile: path atomically:YES]; 

: 내 Detailview에서

내가 다른 자세히보기에로드하려는 경우

NSString *documentDirectory = [self applicationDocumentsDirectory]; 
NSString *path = [documentDirectory stringByAppendingPathComponent:@"Favs.plist"]; 

tempArray = [[NSArray alloc] initWithContentsOfFile:path]; 

array = [[NSMutableArray alloc] initWithArray:tempArray copyItems:YES]; 

NSLog(@"array is: %d", [array count]); 

하지만, 내 배열에 다른 문자열, 그것은 이전 값을 덮어 씁니다 . 어떻게 피할 수 있습니까?

답변

0

NSDictionary 또는 NSArray를 생성하면 배열을 포함하고 해당 전역 사전이나 배열에 파일을 쓸 수 있습니다. 배열을 하나씩 추가해야하는 경우 다음 단계를 따라야합니다. 1. 기존 파일의 내용으로 사전 초기화하기 2. 1 단계에서 생성 한 사전의 변경 가능한 사본을 만듭니다. 3. 추가 파일

전역 배열 더 나은 만약에 사전 4. 쓰기 업데이트 사전에 새로운 배열을 글로벌 사전 단계는 동일하지만 대신 사전의 배열을 사용하는 것보다 사용자의 요구 =)에 맞는