// // YXStepViewController.m // Temperature // // Created by TC on 2025/3/2. // #import "YXStepViewController.h" #import "YXStepTableViewCell.h" #import #import "YXSetWifiViewController.h" #import "YXSetCodeViewController.h" @interface YXStepViewController () @property (weak, nonatomic) UITableView *tableView; @property (copy, nonatomic) NSArray *listArray; @end @implementation YXStepViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; if (self.itemModel.steps == nil || self.itemModel.steps.count == 0) { [self createAlert]; } else { self.listArray = self.itemModel.steps; [self createTableView]; } } -(void)createAlert { UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"该设备暂不能添加" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { [self.navigationController popViewControllerAnimated:YES]; }]; [alert addAction:cancleAction]; [self presentViewController:alert animated:YES completion:nil]; } -(void)createTableView { UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10) style:UITableViewStyleGrouped]; tableView.delegate = self; tableView.dataSource = self; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [tableView registerNib:[UINib nibWithNibName:@"YXStepTableViewCell" bundle:nil] forCellReuseIdentifier:@"stepCellId"]; tableView.backgroundColor = [UIColor colorWithHexString:@"#FEFEFE"]; tableView.showsVerticalScrollIndicator = NO; tableView.showsHorizontalScrollIndicator = NO; [self.view addSubview:tableView]; self.tableView = tableView; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@10); make.right.equalTo(@-15); make.left.equalTo(@15); make.bottom.equalTo(@0); }]; tableView.layer.cornerRadius = 8; [self createTableHeaderView]; [self createTableFooterView]; } -(void)createTableHeaderView { UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)]; headerView.backgroundColor = [UIColor colorWithHexString:@"#FEFEFE"]; self.tableView.tableHeaderView = headerView; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.font = [UIFont boldSystemFontOfSize:22]; titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.textColor = [UIColor colorWithHexString:@"#1E1E1E"]; titleLabel.text = @"配网提示"; [headerView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@10); make.left.equalTo(@15); make.right.equalTo(@-15); make.height.equalTo(@30); }]; } -(void)createTableFooterView { UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 60)]; footerView.backgroundColor = [UIColor colorWithHexString:@"#FEFEFE"]; self.tableView.tableFooterView = footerView; UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [nextBtn setTitle:@"下一步" forState:UIControlStateNormal]; [nextBtn addTarget:self action:@selector(nextBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [nextBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal]; nextBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15]; nextBtn.backgroundColor = [UIColor colorWithHexString:@"#267AFF"]; [footerView addSubview:nextBtn]; [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@45); make.left.equalTo(@0); make.right.equalTo(@0); make.top.equalTo(@15); }]; nextBtn.layer.cornerRadius = 22.5; } -(void)nextBtnAction:(UIButton *)btn { YXSetCodeViewController *vc = [YXSetCodeViewController new]; vc.itemModel = self.itemModel; [self.navigationController pushViewController:vc animated:YES]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.listArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { YXStepTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"stepCellId" forIndexPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone; YXDeviceStepModel *model = self.listArray[indexPath.row]; cell.stepTextLabel.text = model.desc; NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrlHeadImg,model.photo]; [cell.picImgView sd_setImageWithURL:[NSURL URLWithString:urlStr]]; return cell; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc]init]; return headerView; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView = [[UIView alloc]init]; return footerView; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.01; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 280; } /* #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