YMReportReasonView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // YMReportReasonView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/5.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMReportReasonView.h"
  9. #import "YMReportViewModel.h"
  10. #import "YMReportReasonCell.h"
  11. @interface YMReportReasonView()<UITableViewDataSource, UITableViewDelegate>
  12. /// 举报VM
  13. @property (nonatomic, strong) YMReportViewModel *viewModel;
  14. /// 内容列表
  15. @property (nonatomic, strong) UITableView *reportReasonTableView;
  16. @end
  17. @implementation YMReportReasonView
  18. - (void)ym_setupViews{
  19. [self addSubview:self.reportReasonTableView];
  20. [self setNeedsUpdateConstraints];
  21. [self updateConstraintsIfNeeded];
  22. }
  23. - (void)updateConstraints{
  24. [self.reportReasonTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.top.equalTo(self);
  26. make.left.equalTo(self);
  27. make.right.equalTo(self);
  28. make.bottom.equalTo(self);
  29. }];
  30. [super updateConstraints];
  31. }
  32. - (void)ym_bindViewModel:(YMReportViewModel*)viewModel{
  33. if (!viewModel) {
  34. return;
  35. }
  36. _viewModel = viewModel;
  37. @weakify(self)
  38. [[self.viewModel.refreshReportReasonSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  39. @strongify(self)
  40. [self.reportReasonTableView reloadData];
  41. [self.reportReasonTableView layoutIfNeeded];
  42. //刷新高度
  43. CGFloat tableViewHeight = self.reportReasonTableView.contentSize.height;
  44. [self.reportReasonTableView mas_updateConstraints:^(MASConstraintMaker *make) {
  45. make.height.mas_equalTo(tableViewHeight);
  46. }];
  47. }];
  48. }
  49. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  50. return self.viewModel.reportReasonDataArray.count;
  51. }
  52. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  53. YMReportReasonCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMReportReasonCell class])];
  54. if (!cell) {
  55. cell = [[YMReportReasonCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMReportReasonCell class])];
  56. }
  57. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  58. [cell ym_bindViewModel:self.viewModel.reportReasonDataArray[indexPath.item]];
  59. return cell;
  60. }
  61. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  62. return adapt(50);
  63. }
  64. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  65. [self.viewModel.getReportReasonIdSubject sendNext:@(self.viewModel.reportReasonDataArray[indexPath.item].reportReasonId)];
  66. }
  67. - (UITableView *)reportReasonTableView{
  68. if (!_reportReasonTableView) {
  69. _reportReasonTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  70. _reportReasonTableView.delegate = self;
  71. _reportReasonTableView.dataSource = self;
  72. _reportReasonTableView.estimatedRowHeight = 0;
  73. _reportReasonTableView.estimatedSectionHeaderHeight = 0;
  74. _reportReasonTableView.estimatedSectionFooterHeight = 0;
  75. _reportReasonTableView.showsVerticalScrollIndicator = NO;
  76. _reportReasonTableView.showsHorizontalScrollIndicator = NO;
  77. _reportReasonTableView.scrollEnabled = NO;
  78. _reportReasonTableView.separatorColor = UIColor.clearColor;
  79. _reportReasonTableView.backgroundColor = UIColor.whiteColor;
  80. [_reportReasonTableView registerClass:[YMReportReasonCell class] forCellReuseIdentifier:NSStringFromClass([YMReportReasonCell class])];
  81. }
  82. return _reportReasonTableView;
  83. }
  84. @end