-
(void)viewDidLoad {
[super viewDidLoad];
[self setNav];[[DataManager shareManage]open];
[[DataManager shareManage]create];
} -
(void)setNav{
if (self.typeID == 1) {
self.title = @“添加數據”;
}else{
self.title = @“更新數據”;
self.name.text = _model.name;
self.age.text = _model.age;
self.view.backgroundColor=[UIColor whiteColor];
UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(200, 200, 40, 40)];
btn.backgroundColor=[UIColor greenColor];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(kkk) forControlEvents:UIControlEventTouchUpInside];NSURL *url=[[NSBundle mainBundle] URLForResource:_filtname withExtension:@"mp3"]; play=[[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
// [play play];
}
self.view.backgroundColor = [UIColor redColor];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@“更新” style:UIBarButtonItemStylePlain target:self action:@selector(saveBtnClick)];
}
//更新
-
(void)saveBtnClick{
Student *model = [Student new];model.name = _name.text;
model.age = _age.text;
if (self.typeID == 1) {
[[DataManager shareManage]insert:model];
}else{
[[DataManager shareManage]update:model];
}
[[DataManager shareManage]close];
[self.navigationController popViewControllerAnimated:YES];
}