Objective-C在切换视图时无法保存NSMutableArray

时间:2011-12-09 14:41:49

标签: iphone objective-c ios nsmutablearray xcode4.2

我正在使用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]
}

谢谢

0 个答案:

没有答案