我正在使用XCode 4.2并且在切换视图时我一直在尝试保存NSMutableArray,但是当我使用NSMutable数组回到视图时数据总是消失我使用以下函数
-(void)saveData{
[NSKeyedArchiver archiveRootObject:[data copy] toFile: [self dataFilePath]];
}
-(NSString)dataFilePath{
NSString *dataFilePath;
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory , NSUserDomainMask ,YES);
NSString *documentDirectory =[paths objectAtIndex:0];
dataFilePath= [DocumentDirectory stringByAppendingPathComponent:@"history.txt"];
return dataFilePath;
}
-(void)viewWillDisappear:(BOOL)animated{
[self saveData]
}
谢谢