0
我正在向NSArray添加一個NSString,並在另一個Tableview中讀取它,該工作完美無瑕。將NSArray添加到.plist
在我的DetailView:
NSString *documentDirectory = [self applicationDocumentsDirectory];
NSString *path = [documentDirectory stringByAppendingPathComponent:@"Favs.plist"];
NSArray *Array = [[NSArray alloc] initWithObjects:self.title, nil];
[Array writeToFile: path atomically:YES];
在我FavTableView:
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]);
但是,如果我想加載,在不同的詳細信息視圖,另一個字符串我的數組,它會覆蓋舊值。我如何避免這種情況?