RDSSelectDeviceSubVC.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // RDSSelectDeviceSubVC.m
  3. // Temperature
  4. //
  5. // Created by 姓二名哈字富贵儿 on 2023/8/17.
  6. //
  7. #import "RDSSelectDeviceSubVC.h"
  8. #import "RDSDeviceTypeCell.h"
  9. @interface RDSSelectDeviceSubVC () <UITableViewDelegate, UITableViewDataSource>
  10. @property (nonatomic, strong) UITableView *tableView;
  11. @property (nonatomic, strong) NSArray *dataSource;
  12. @end
  13. @implementation RDSSelectDeviceSubVC
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. [self configSubviews];
  17. }
  18. - (void)configSubviews {
  19. self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  20. self.tableView.backgroundColor = [UIColor colorWithHexString:@"#FBFBFB"];
  21. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  22. self.tableView.delegate = self;
  23. self.tableView.dataSource = self;
  24. [self.tableView registerClass:[RDSDeviceTypeCell class] forCellReuseIdentifier:NSStringFromClass([RDSDeviceTypeCell class])];
  25. [self.view addSubview:self.tableView];
  26. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.left.right.bottom.equalTo(self.view);
  28. make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
  29. }];
  30. }
  31. - (void)reloadDataWithDataSource:(NSArray *)dataSource {
  32. if (!dataSource) {
  33. self.dataSource = [NSArray array];
  34. } else {
  35. self.dataSource = [dataSource copy];
  36. }
  37. [self.tableView reloadData];
  38. }
  39. #pragma mark - UITableViewDataSource
  40. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  41. return self.dataSource.count;
  42. }
  43. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  44. return 1;
  45. }
  46. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  47. RDSDeviceTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([RDSDeviceTypeCell class]) forIndexPath:indexPath];
  48. cell.deviceTypeModel = self.dataSource[indexPath.section];
  49. return cell;
  50. }
  51. - (NSArray *)dataSource {
  52. if (!_dataSource) {
  53. _dataSource = [NSArray array];
  54. }
  55. return _dataSource;
  56. }
  57. @end