2017-07-15 91 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中支持 数据类型有: 阵列, 字典, 字符串, 号码, 数据, 日期, 布尔