2017-07-15 96 views
2

我需要將數據從2個數組保存到文檔目錄,第一個保存,但第二個不是!將NSArray數據保存到NSDocumentDirectory中的2個文件中

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 


    NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; 

    NSString *rangePath = [documentsDir stringByAppendingPathComponent:@"Range.plist"]; 
    NSString *indexPath = [documentsDir stringByAppendingPathComponent:@"Select.plist"]; 

    [finalMutable writeToFile:rangePath atomically:YES]; 
    [finalIndex writeToFile:indexPath atomically:YES]; 

} 

更新:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [finalIndex addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]; 
} 
+0

PLS添加什麼finalMutable和finalIndex包含,finalIndex一定是問題 –

+0

它們都有相同的,這是NSLog:finalMutable count:5,finalIndex count:5 –

回答

1

你是無法保存第二個選項,因爲finalIndex數組包含NSIndexPath objects.NSIndexPath對象不能存儲在plist中的文件。在plist中支持 數據類型有: 陣列, 字典, 字符串, 號碼, 數據, 日期, 布爾

相關問題