YMAboutUsViewController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // YMAboutUsViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAboutUsViewController.h"
  9. #import "YMAboutUsViewModel.h"
  10. #import "YMAboutUsInfoView.h"
  11. #import "YMAboutUsCell.h"
  12. @interface YMAboutUsViewController()<UITableViewDataSource, UITableViewDelegate>
  13. /// 关于我们VM
  14. @property (nonatomic, strong) YMAboutUsViewModel *viewModel;
  15. /// 信息视图
  16. @property (nonatomic, strong) YMAboutUsInfoView *infoView;
  17. /// 内容列表
  18. @property (nonatomic, strong) UITableView *contentTableView;
  19. @end
  20. @implementation YMAboutUsViewController
  21. @dynamic viewModel;
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. }
  25. - (void)ym_setupViews{
  26. [self.view addSubview:self.contentTableView];
  27. [self.view setNeedsUpdateConstraints];
  28. [self.view updateConstraintsIfNeeded];
  29. }
  30. - (void)updateViewConstraints{
  31. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.equalTo(self.view).offset(kYMNavHeight);
  33. make.left.equalTo(self.view);
  34. make.right.equalTo(self.view);
  35. make.bottom.equalTo(self.view);
  36. }];
  37. [super updateViewConstraints];
  38. }
  39. - (void)ym_bindViewModel{
  40. [self.infoView ym_bindViewModel:self.viewModel];
  41. [self.viewModel getAboutUsListData];
  42. @weakify(self)
  43. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  44. @strongify(self)
  45. [self.contentTableView reloadData];
  46. }];
  47. }
  48. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  49. return self.viewModel.listDataArray.count;
  50. }
  51. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  52. YMAboutUsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMAboutUsCell class])];
  53. if (!cell) {
  54. cell = [[YMAboutUsCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMAboutUsCell class])];
  55. }
  56. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  57. [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]];
  58. return cell;
  59. }
  60. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  61. return adapt(50);
  62. }
  63. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  64. [self.viewModel.aboutUsFunctionsOperationSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].aboutUsFunctionsType)];
  65. }
  66. - (YMAboutUsInfoView *)infoView{
  67. if (!_infoView) {
  68. _infoView = [[YMAboutUsInfoView alloc]initWithFrame:CGRectMake(0, 0, kFrameWidth, adapt(300))];
  69. }
  70. return _infoView;
  71. }
  72. - (UITableView *)contentTableView{
  73. if (!_contentTableView) {
  74. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  75. _contentTableView.delegate = self;
  76. _contentTableView.dataSource = self;
  77. _contentTableView.estimatedRowHeight = 0;
  78. _contentTableView.estimatedSectionHeaderHeight = 0;
  79. _contentTableView.estimatedSectionFooterHeight = 0;
  80. _contentTableView.showsVerticalScrollIndicator = NO;
  81. _contentTableView.showsHorizontalScrollIndicator = NO;
  82. _contentTableView.separatorColor = UIColor.clearColor;
  83. _contentTableView.backgroundColor = UIColor.whiteColor;
  84. [_contentTableView registerClass:[YMAboutUsCell class] forCellReuseIdentifier:NSStringFromClass([YMAboutUsCell class])];
  85. _contentTableView.tableHeaderView = self.infoView;
  86. }
  87. return _contentTableView;
  88. }
  89. @end