ios24-数据持久化-对象归档(2)
NSKeyedUnarchiver *unArchiver=[[NSKeyedUnarchiver alloc]initForReadingWithData:data];
//完成student对象的实例化
Student *stu=[unArchiver decodeObjectForKey:@"stuobj"];
[unArchiver finishDecoding];
//设置显示
tfId.text=stu.studentId;
tfName.text=stu.studentName;
tfClass.text=stu.studentClass;
}
//进行解压
}
//
-(NSString *)getFilePath{
//设置文件保存的路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//获取documents路径
NSString *documentPath = [paths lastObject];
//定义全路径
NSString *savePath = [documentPath stringByAppendingPathComponent:@"student.achiver"];
return savePath;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
tfId.delegate=self;
tfName.delegate=self;
tfClass.delegate=self;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
2.建立一个student类
//
// Student.h
// ios24-saveObjectToFile
相关新闻>>
- 发表评论
-
- 最新评论 更多>>