RDSSelectDeviceSubVC.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // RDSSelectDeviceSubVC.m
  3. // Temperature
  4. //
  5. // Created by 姓二名哈字富贵儿 on 2023/8/17.
  6. //
  7. #import "RDSSelectDeviceSubVC.h"
  8. #import "RDSDeviceTypeCell.h"
  9. #import "RDSResetDeviceVC.h"
  10. @interface RDSSelectDeviceSubVC () <UITableViewDelegate, UITableViewDataSource>
  11. @property (nonatomic, strong) UITableView *tableView;
  12. @property (nonatomic, strong) NSArray *dataSource;
  13. @end
  14. @implementation RDSSelectDeviceSubVC
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. [self configSubviews];
  18. }
  19. - (void)configSubviews {
  20. self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  21. self.tableView.backgroundColor = [UIColor colorWithHexString:@"#FBFBFB"];
  22. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  23. self.tableView.delegate = self;
  24. self.tableView.dataSource = self;
  25. [self.tableView registerClass:[RDSDeviceTypeCell class] forCellReuseIdentifier:NSStringFromClass([RDSDeviceTypeCell class])];
  26. [self.view addSubview:self.tableView];
  27. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.right.bottom.equalTo(self.view);
  29. make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
  30. }];
  31. }
  32. - (void)reloadDataWithDataSource:(NSArray *)dataSource {
  33. if (!dataSource) {
  34. self.dataSource = [NSArray array];
  35. } else {
  36. self.dataSource = [dataSource copy];
  37. }
  38. [self.tableView reloadData];
  39. }
  40. #pragma mark - UITableViewDataSource
  41. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  42. return self.dataSource.count;
  43. }
  44. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  45. return 1;
  46. }
  47. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  48. RDSDeviceTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([RDSDeviceTypeCell class]) forIndexPath:indexPath];
  49. cell.deviceTypeModel = self.dataSource[indexPath.section];
  50. return cell;
  51. }
  52. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  53. RDSDeviceTypeModel *deviceTypeModel = self.dataSource[indexPath.section];
  54. if ([deviceTypeModel.code isEqualToString:@"YXK-P/DN-JF-8"]) {
  55. [TheAlertCtrl rds_alertWithTitle:@"提示" message:@"该功能正在开发中,敬请期待!"];
  56. return;
  57. }
  58. RDSResetDeviceVC *resetDeviceVC = [[RDSResetDeviceVC alloc] init];
  59. resetDeviceVC.deviceTypeModel = deviceTypeModel;
  60. [self.parentViewController.navigationController pushViewController:resetDeviceVC animated:YES];
  61. }
  62. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  63. return 20;
  64. }
  65. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  66. return CGFLOAT_MIN;
  67. }
  68. - (NSArray *)dataSource {
  69. if (!_dataSource) {
  70. _dataSource = [NSArray array];
  71. }
  72. return _dataSource;
  73. }
  74. @end