// // NewStepVC.m // tongxin // // Created by Apple on 2020/4/10. // Copyright © 2020 xTT. All rights reserved. // #import "NewStepVC.h" #import "TableCell.h" #import "Step.h" #import "NewStepChartCell.h" #import "MyUILabel.h" @interface NewStepVC () @property (strong, nonatomic) UITableView *myTableView; /// 最近一周的计步的数据数组 @property (strong, nonatomic) NSArray *dataList; @property (assign, nonatomic) int switchStatus; /// 今天的步数 @property (assign, nonatomic) int todayData; @end @implementation NewStepVC @synthesize myDataSource = _myDataSource; -(NSMutableArray *)myDataSource{ if(!_myDataSource){ _myDataSource = [NSMutableArray arrayWithArray:@[@[@"图表"]]]; //,@[@"计步开关"] remove by lsz 2020-12-14 } return _myDataSource; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self loadData]; } - (void)viewDidLoad { [super viewDidLoad]; [self initTableView]; self.title = @"计步"; } - (void)loadData{ //今天 NSString *today = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" date:[NSDate date]]; //一周前的时间 NSString *lastWeekDay = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" date:[myHelper ddpGetExpectTimestamp:0 month:0 day:-6]]; WEAKSELF [Step getNewStepDataWithStartDate:lastWeekDay date:today Success:^(NSArray *stepList, int switchStatus, int todayData) { weakSelf.dataList = stepList; weakSelf.switchStatus = switchStatus; weakSelf.todayData = todayData; [weakSelf.myTableView reloadData]; } failure:^(NSError *error) { }]; } - (void)initTableView{ _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, iPhoneX_NavHeight, ScreenWidth, ScreenHeight-iPhoneX_NavHeight) style:UITableViewStylePlain]; _myTableView.backgroundColor = KKWhiteColorColor; _myTableView.delegate = self; _myTableView.dataSource = self; [self.view addSubview:_myTableView]; _myTableView.bounces = NO; //禁止弹跳 _myTableView.showsHorizontalScrollIndicator = NO; _myTableView.showsVerticalScrollIndicator = NO; //去线 _myTableView.separatorStyle = UITableViewCellSelectionStyleNone; // iOS 11 系统 tableView 会自动调整高度 在 Gounp 模式下 头部的高度会有问题 ,需要对 预设的高度设置为0 _myTableView.estimatedRowHeight = 0; _myTableView.estimatedSectionHeaderHeight = 0; _myTableView.estimatedSectionFooterHeight = 0; [_myTableView registerNib:[UINib nibWithNibName:@"NewStepChartCell" bundle:nil] forCellReuseIdentifier:@"NewStepChartCellID"]; [_myTableView registerClass:[baseCell class] forCellReuseIdentifier:@"baseCell"]; // add by lsz 2021-06-10 footer MyUILabel *footer = [[MyUILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 36)]; footer.edgeInsets = UIEdgeInsetsMake(8, 16, 8, 16); footer.font = Font_(12); footer.adjustsFontSizeToFitWidth = YES; footer.numberOfLines = 0; footer.baselineAdjustment = UIBaselineAdjustmentAlignCenters; [footer setTextColor:KKGrey163]; [footer setText:@"温馨提示:每天累计步数,到24点清零"]; _myTableView.tableHeaderView = footer; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.myDataSource.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.myDataSource[section] count]; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 0) { return 0.01; } return 15 * FIX_SCREEN; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.01; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *title = self.myDataSource[indexPath.section][indexPath.row]; if([title isEqualToString:@"图表"]){ return 680; }else{ return 49; } } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *title = self.myDataSource[indexPath.section][indexPath.row]; WEAKSELF if([title isEqualToString:@"图表"]){ NewStepChartCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewStepChartCellID" forIndexPath:indexPath]; if(_dataList){ [cell setStepDataList:_dataList WithTodayData:_todayData]; } return cell; } if(indexPath.section == 1 && indexPath.row == 0) { baseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewStepBaseCell"]; if (!cell) { cell = [[baseCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"NewStepBaseCell"]; cell.textLabel.font = DefineFontSize; cell.textLabel.text = title; UISwitch *uiSwitch = [[UISwitch alloc] init]; cell.accessoryView = uiSwitch; [uiSwitch addTarget:cell action:@selector(cellClick:) forControlEvents:UIControlEventValueChanged]; } UISwitch *uiSwitch = (UISwitch *)cell.accessoryView; uiSwitch.onTintColor = mainColor; uiSwitch.on = self.switchStatus; cell.textLabel.text = title; cell.block = ^(UISwitch *uiSwitch, TextFieldCell *blockCell){ //切换开关 xLog(@"切换开关uiSwitch.on : %d", uiSwitch.on); [Step postNewStepSwithStatus:uiSwitch.on Success:^(id responseObject) { [UICommon MessageSuccessText:@"修改成功" isImg:YES]; weakSelf.switchStatus = uiSwitch.on; [weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationNone]; } failure:^(NSError *error) { [weakSelf.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationNone]; }]; }; return cell; } return nil; } @end