// // VoiceAlarmViewController.m // watch // // Created by xTT on 2017/7/12. // Copyright © 2017年 xTT. All rights reserved. // #import "VoiceAlarmViewController.h" #import "AddVAViewController.h" #import "VoiceAlarm.h" #import "VoiceAlarmTableViewCell.h" #import "CommonTableView.h" @interface VoiceAlarmViewController () @end @implementation VoiceAlarmViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.zx_navTitle = @"闹钟"; [self zx_setRightBtnWithText:@"添加" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { [self gotoAddVoiceAlarmVC]; }]; self.myTableView.frame = CGRectMake(16, iPhoneX_NavHeight, ScreenWidth-32, ScreenHeight-iPhoneX_NavHeight); self.myTableView.separatorStyle = UITableViewCellSelectionStyleNone; [self.myTableView registerClass:VoiceAlarmTableViewCell.class forCellReuseIdentifier:NSStringFromClass(VoiceAlarmTableViewCell.class)]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; WEAKSELF [VoiceAlarm getObjsSuccess:^(NSMutableArray *arr) { weakSelf.myDataSource = [[NSMutableArray alloc] init]; [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [weakSelf.myDataSource addObject:obj]; }]; [weakSelf.myTableView reloadData]; } failure:^(NSError *error){ if (!error) { } }]; } -(void)emptyDataSetView { [self gotoAddVoiceAlarmVC]; } - (void)gotoAddVoiceAlarmVC { [UICommon PusXibViewController:[AddVAViewController new] :@"AddVAViewController"]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.myDataSource.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 12; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 146; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { VoiceAlarm *voiceAlarm = self.myDataSource[indexPath.section]; VoiceAlarmTableViewCell *cell = [VoiceAlarmTableViewCell cellWithTableView:tableView indexPath:indexPath]; cell.voiceAlarmModel = voiceAlarm; cell.BlockBtnClick = ^(UISwitch * _Nonnull sender, id _Nonnull blockCell) { voiceAlarm.status = @(sender.on); [voiceAlarm saveSuccess:^{ voiceAlarm.status = @(sender.on); [self.myTableView reloadData]; }failure:^{ [self.myTableView reloadData]; }]; }; // baseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"baseCell"]; // if (!cell) { // cell = [[baseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"baseCell"]; // cell.backgroundColor = KKClearColor; // // UIView *bg = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKWhiteColorColor]; // [cell addSubview:bg]; // [bg mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.right.equalTo(cell); // make.top.equalTo(cell); // make.bottom.equalTo(cell.mas_bottom); // }]; // // } // // for (UILabel *labels in cell.subviews) // { // [cell removeFromSuperview]; // } // // UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(20) textColor:KKBlack20 text:voiceAlarm.time Radius:0]; // [cell addSubview:timeLabel]; // [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(cell).offset(15); // make.top.equalTo(cell).offset(15); // }]; // // UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKBlack20 text:voiceAlarm.text Radius:10]; // titleLabel.backgroundColor = [voiceAlarm.status boolValue] ? RGB(255, 243, 236) : RGB(240, 240, 240); // titleLabel.textColor = [voiceAlarm.status boolValue] ? mainColor : KKGrey163; // [cell addSubview:titleLabel]; // CGRect ww = [UICommon GetTextWidth:voiceAlarm.text ViewHeight:20 fontSize:Font_(12) type:@"w"]; // [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(timeLabel.mas_right).offset(5); // make.centerY.equalTo(timeLabel); // make.size.mas_equalTo(CGSizeMake(ww.size.width+20, 20)); // }]; // // UILabel *msgLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:Font_(14) textColor:KKGrey102 text:[myHelper getWeekDayStr:[voiceAlarm week]] Radius:0]; // [cell addSubview:msgLabel]; // [msgLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.right.equalTo(cell).inset(15); // make.top.equalTo(timeLabel.mas_bottom).offset(10); // }]; // // UIImageView *line = [UIImageView new]; // line.backgroundColor = RGB(240, 240, 240); // [cell addSubview:line]; // [line mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.right.equalTo(cell).inset(15); // make.bottom.equalTo(msgLabel.mas_bottom).offset(15); // make.height.mas_equalTo(0.5); // }]; // // UISwitch *uiSwitch = [[UISwitch alloc] init]; // [uiSwitch addTarget:cell // action:@selector(cellClick:) // forControlEvents:UIControlEventValueChanged]; // uiSwitch.onTintColor = mainColor; // uiSwitch.on = [voiceAlarm.status boolValue]; // [cell addSubview:uiSwitch]; // [uiSwitch mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.equalTo(cell.mas_right).inset(15); // make.top.equalTo(line.mas_bottom).offset(15); // make.size.mas_equalTo(CGSizeMake(48, 28)); // }]; // // cell.block = ^(UISwitch *uiSwitch, TextFieldCell *blockCell){ // voiceAlarm.status = @(uiSwitch.on); // [voiceAlarm saveSuccess:^{ // [self.myTableView reloadData]; // }failure:^{ // uiSwitch.on = !uiSwitch.on; // voiceAlarm.status = @(uiSwitch.on); // }]; // }; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ VoiceAlarm *voiceAlarm = self.myDataSource[indexPath.section]; // [self performSegueWithIdentifier:@"goAddVoiceAlarmVC" sender:voiceAlarm]; UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; AddVAViewController *vc = [sb instantiateViewControllerWithIdentifier:@"AddVAViewController"]; vc.isAdd = YES; vc.infoVoiceAlarm = voiceAlarm; [self.navigationController pushViewController:vc animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. if (sender) { [segue.destinationViewController setValue:sender forKey:@"infoVoiceAlarm"]; } } @end