RDSSelectDeviceSubVC.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. - (NSArray *)dataSource {
  63. if (!_dataSource) {
  64. _dataSource = [NSArray array];
  65. }
  66. return _dataSource;
  67. }
  68. @end