首先在AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中初始话本地文件:[color=red]NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path=[paths objectAtIndex:0];
NSLog(@"%@",path);
self.filename=[path stringByAppendingPathComponent:@"test.plist"];[/color]//test.plitst文件创建;
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[color=red]NSMutableArray *temp=[NSKeyedUnarchiver unarchiveObjectWithFile:appDelegate.filename];//先用数组读取本地数据
if (temp == nil) {
temp = [[NSMutableArray alloc]initWithCapacity:0];//
}
NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:m_labelpeople.text,@"1",m_labelrestaurant.text,@"2",m_labelpackage.text,@"3",price,@"4", nil];
[temp addObject:dic];//在数组中继续添加界面中label的值
[NSKeyedArchiver archiveRootObject:temp toFile:appDelegate.filename];//将数组中值保存到本地
[/color]
self.listdata = [NSKeyedUnarchiver unarchiveObjectWithFile:appDelegate.filename];//用listdata数组读取本地数据
NSString *path=[paths objectAtIndex:0];
NSLog(@"%@",path);
self.filename=[path stringByAppendingPathComponent:@"test.plist"];[/color]//test.plitst文件创建;
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[color=red]NSMutableArray *temp=[NSKeyedUnarchiver unarchiveObjectWithFile:appDelegate.filename];//先用数组读取本地数据
if (temp == nil) {
temp = [[NSMutableArray alloc]initWithCapacity:0];//
}
NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:m_labelpeople.text,@"1",m_labelrestaurant.text,@"2",m_labelpackage.text,@"3",price,@"4", nil];
[temp addObject:dic];//在数组中继续添加界面中label的值
[NSKeyedArchiver archiveRootObject:temp toFile:appDelegate.filename];//将数组中值保存到本地
[/color]
self.listdata = [NSKeyedUnarchiver unarchiveObjectWithFile:appDelegate.filename];//用listdata数组读取本地数据