// // SOSViewController.m // watch // // Created by xTT on 2017/7/17. // Copyright © 2017年 xTT. All rights reserved. // #import "SOSViewController.h" #import "SOS.h" @interface SOSViewController () @end @implementation SOSViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.zx_navTitle = @"SOS号码"; [self zx_setRightBtnWithText:@"保存" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { [self rightBarItemClick]; }]; [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.equalTo(self.view).offset(iPhoneX_NavHeight); make.bottom.equalTo(self.view.mas_bottom); }]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; WEAKSELF [SOS getSOSSuccess:^(NSMutableArray *arr) { [weakSelf.myDataSource removeAllObjects]; [weakSelf.myDataSource addObjectsFromArray:@[arr]]; [weakSelf.myTableView reloadData]; } failure:^{}]; } - (void)rightBarItemClick { __block BOOL hasError = NO; [[self.myDataSource firstObject] enumerateObjectsUsingBlock:^(SOS * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.phone.length > 0) { if (obj.phone.length < 3 || obj.phone.length > 15) { hasError = YES; *stop = YES; } } }]; if (hasError) { [SVProgressHUD showErrorWithStatus:@"号码为3~15位"]; }else{ [SOS saveSOS:[self.myDataSource firstObject] success:^{ [self goBack:nil]; } failure:^{}]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ SOS *sos = self.myDataSource[indexPath.section][indexPath.row]; TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TextFieldCell"]; if (!cell) { cell = [[TextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TextFieldCell"]; cell.accessoryType = UITableViewCellAccessoryNone; cell.textField.keyboardType = UIKeyboardTypePhonePad; cell.textLabel.text = [NSString stringWithFormat:@"SOS号码%zi",indexPath.row + 1]; cell.textField.placeholder = @"请输入SOS号码"; } cell.textField.text = sos.phone; cell.block = ^(NSString *sender, TextFieldCell *cell) { sos.phone = sender; }; return cell; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleNone; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if (section == self.myDataSource.count - 1) { return 10 + 70 + 10; } return [super tableView:tableView heightForFooterInSection:section]; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; if (section == self.myDataSource.count - 1) { UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake((SWIDTH - 310 * FIX_SCREEN) / 2, 10, 310 * FIX_SCREEN, 120)]; lable.text = @"1.请为设备设置紧急号码,设备按下SOS按键,即可拨打上方设置的号码\n2.如果您想删除SOS号码,请将号码删除,然后点击保存\n3.设备使用SOS功能时,会依次拨打下方号码,轮打3遍结束"; lable.numberOfLines = 0; lable.font = [UIFont systemFontOfSize:14]; lable.textColor = [UIColor systemGrayColor]; [view addSubview:lable]; } return view; } - (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. } */ @end