YXStepViewController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // YXStepViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/3/2.
  6. //
  7. #import "YXStepViewController.h"
  8. #import "YXStepTableViewCell.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import "YXSetWifiViewController.h"
  11. #import "YXSetCodeViewController.h"
  12. @interface YXStepViewController ()<UITableViewDataSource,UITableViewDelegate>
  13. @property (weak, nonatomic) UITableView *tableView;
  14. @property (copy, nonatomic) NSArray *listArray;
  15. @end
  16. @implementation YXStepViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.view.backgroundColor = [UIColor whiteColor];
  20. if (self.itemModel.steps == nil || self.itemModel.steps.count == 0) {
  21. [self createAlert];
  22. } else {
  23. self.listArray = self.itemModel.steps;
  24. [self createTableView];
  25. }
  26. }
  27. -(void)createAlert
  28. {
  29. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"该设备暂不能添加" preferredStyle:UIAlertControllerStyleAlert];
  30. UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  31. [self.navigationController popViewControllerAnimated:YES];
  32. }];
  33. [alert addAction:cancleAction];
  34. [self presentViewController:alert animated:YES completion:nil];
  35. }
  36. -(void)createTableView
  37. {
  38. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10) style:UITableViewStyleGrouped];
  39. tableView.delegate = self;
  40. tableView.dataSource = self;
  41. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. [tableView registerNib:[UINib nibWithNibName:@"YXStepTableViewCell" bundle:nil] forCellReuseIdentifier:@"stepCellId"];
  43. tableView.backgroundColor = [UIColor colorWithHexString:@"#FEFEFE"];
  44. tableView.showsVerticalScrollIndicator = NO;
  45. tableView.showsHorizontalScrollIndicator = NO;
  46. [self.view addSubview:tableView];
  47. self.tableView = tableView;
  48. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(@10);
  50. make.right.equalTo(@-15);
  51. make.left.equalTo(@15);
  52. make.bottom.equalTo(@0);
  53. }];
  54. tableView.layer.cornerRadius = 8;
  55. [self createTableHeaderView];
  56. [self createTableFooterView];
  57. }
  58. -(void)createTableHeaderView
  59. {
  60. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)];
  61. headerView.backgroundColor = [UIColor colorWithHexString:@"#FEFEFE"];
  62. self.tableView.tableHeaderView = headerView;
  63. UILabel *titleLabel = [[UILabel alloc] init];
  64. titleLabel.font = [UIFont boldSystemFontOfSize:22];
  65. titleLabel.textAlignment = NSTextAlignmentCenter;
  66. titleLabel.textColor = [UIColor colorWithHexString:@"#1E1E1E"];
  67. titleLabel.text = @"配网提示";
  68. [headerView addSubview:titleLabel];
  69. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.top.equalTo(@10);
  71. make.left.equalTo(@15);
  72. make.right.equalTo(@-15);
  73. make.height.equalTo(@30);
  74. }];
  75. }
  76. -(void)createTableFooterView
  77. {
  78. UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 60)];
  79. footerView.backgroundColor = [UIColor colorWithHexString:@"#FEFEFE"];
  80. self.tableView.tableFooterView = footerView;
  81. UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  82. [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
  83. [nextBtn addTarget:self action:@selector(nextBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  84. [nextBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  85. nextBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
  86. nextBtn.backgroundColor = [UIColor colorWithHexString:@"#267AFF"];
  87. [footerView addSubview:nextBtn];
  88. [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.height.equalTo(@45);
  90. make.left.equalTo(@0);
  91. make.right.equalTo(@0);
  92. make.top.equalTo(@15);
  93. }];
  94. nextBtn.layer.cornerRadius = 22.5;
  95. }
  96. -(void)nextBtnAction:(UIButton *)btn
  97. {
  98. YXSetCodeViewController *vc = [YXSetCodeViewController new];
  99. vc.itemModel = self.itemModel;
  100. [self.navigationController pushViewController:vc animated:YES];
  101. }
  102. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  103. {
  104. return 1;
  105. }
  106. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  107. {
  108. return self.listArray.count;
  109. }
  110. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  111. {
  112. YXStepTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"stepCellId" forIndexPath:indexPath];
  113. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  114. YXDeviceStepModel *model = self.listArray[indexPath.row];
  115. cell.stepTextLabel.text = model.desc;
  116. NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrlHeadImg,model.photo];
  117. [cell.picImgView sd_setImageWithURL:[NSURL URLWithString:urlStr]];
  118. return cell;
  119. }
  120. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  121. {
  122. UIView *headerView = [[UIView alloc]init];
  123. return headerView;
  124. }
  125. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  126. {
  127. UIView *footerView = [[UIView alloc]init];
  128. return footerView;
  129. }
  130. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  131. {
  132. return 0.01;
  133. }
  134. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  135. {
  136. return 0.01;
  137. }
  138. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  139. {
  140. return 280;
  141. }
  142. /*
  143. #pragma mark - Navigation
  144. // In a storyboard-based application, you will often want to do a little preparation before navigation
  145. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  146. // Get the new view controller using [segue destinationViewController].
  147. // Pass the selected object to the new view controller.
  148. }
  149. */
  150. @end