我使用plist来存储在uitextfields中输入的数据。但是,当我重新启动应用程序时,先前输入的所有数据都被删除了。如何在plist中保留数据。我有一个UITableView,当一个单元格被触摸时,一个带有两个UITextFields的视图出现。名称字段和说明字段。我以这种方式存储数据。
我的代码是。
-(void)save:(id)sender
{
indexOfDataArray = temp;
NSString *string1 = [[NSString alloc]init];
NSString *string2 = [[NSString alloc]init];
string1 = nameField.text;
string2 = descriptionField.text;
NSDictionary *myDict = [[NSDictionary alloc] initWithObjectsAndKeys:string2, string1, nil];
//NSDictionary *myDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"value", string2, @"key", string1, @"index", [NSNumber numberWithInt:indexOfDataArray], nil];
[myArray addObject:myDict];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"tableVideoData.plist"];
[myArray writeToFile:path atomically:YES];
UIAlertView *alertMesage = [[UIAlertView alloc] initWithTitle: @"Save Alert" message:@"The data entered is saved" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil] ;
[alertMesage show];
[alertMesage release];
}
文件的路径是
/Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/31DEFEE7-A468-44BD-B044-53BEA3391C1A/Documents
但问题是,每次重新启动应用程序时,都会在新文件夹中的新plist文件中创建数据。那么,如何将数据存储在一个plist中呢?
谢谢您。