123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // YMReportReasonView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/5.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMReportReasonView.h"
- #import "YMReportViewModel.h"
- #import "YMReportReasonCell.h"
- @interface YMReportReasonView()<UITableViewDataSource, UITableViewDelegate>
- /// 举报VM
- @property (nonatomic, strong) YMReportViewModel *viewModel;
- /// 内容列表
- @property (nonatomic, strong) UITableView *reportReasonTableView;
- @end
- @implementation YMReportReasonView
- - (void)ym_setupViews{
- [self addSubview:self.reportReasonTableView];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
- [self.reportReasonTableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self);
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self);
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMReportViewModel*)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
-
- @weakify(self)
- [[self.viewModel.refreshReportReasonSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.reportReasonTableView reloadData];
- [self.reportReasonTableView layoutIfNeeded];
- //刷新高度
- CGFloat tableViewHeight = self.reportReasonTableView.contentSize.height;
- [self.reportReasonTableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(tableViewHeight);
- }];
-
- }];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.viewModel.reportReasonDataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- YMReportReasonCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMReportReasonCell class])];
- if (!cell) {
- cell = [[YMReportReasonCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMReportReasonCell class])];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell ym_bindViewModel:self.viewModel.reportReasonDataArray[indexPath.item]];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return adapt(50);
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [self.viewModel.getReportReasonIdSubject sendNext:@(self.viewModel.reportReasonDataArray[indexPath.item].reportReasonId)];
- }
- - (UITableView *)reportReasonTableView{
- if (!_reportReasonTableView) {
- _reportReasonTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _reportReasonTableView.delegate = self;
- _reportReasonTableView.dataSource = self;
- _reportReasonTableView.estimatedRowHeight = 0;
- _reportReasonTableView.estimatedSectionHeaderHeight = 0;
- _reportReasonTableView.estimatedSectionFooterHeight = 0;
- _reportReasonTableView.showsVerticalScrollIndicator = NO;
- _reportReasonTableView.showsHorizontalScrollIndicator = NO;
- _reportReasonTableView.scrollEnabled = NO;
- _reportReasonTableView.separatorColor = UIColor.clearColor;
- _reportReasonTableView.backgroundColor = UIColor.whiteColor;
- [_reportReasonTableView registerClass:[YMReportReasonCell class] forCellReuseIdentifier:NSStringFromClass([YMReportReasonCell class])];
- }
- return _reportReasonTableView;
- }
- @end
|