RDSSelectDeviceSubVC.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. RDSResetDeviceVC *resetDeviceVC = [[RDSResetDeviceVC alloc] init];
  55. resetDeviceVC.deviceTypeModel = deviceTypeModel;
  56. [self.parentViewController.navigationController pushViewController:resetDeviceVC animated:YES];
  57. }
  58. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  59. return 20;
  60. }
  61. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  62. return CGFLOAT_MIN;
  63. }
  64. - (NSArray *)dataSource {
  65. if (!_dataSource) {
  66. _dataSource = [NSArray array];
  67. }
  68. return _dataSource;
  69. }
  70. @end