// // YMEditProfileInfoView.m // MSYOUPAI // // Created by YoMi on 2024/2/18. // Copyright © 2024 MS. All rights reserved. // #import "YMEditProfileInfoView.h" #import "YMEditProfileViewModel.h" #import "YMEditProfileInfoCell.h" @interface YMEditProfileInfoView () /// 编辑资料VM @property (nonatomic, strong) YMEditProfileViewModel *viewModel; /// 信息列表 @property (nonatomic, strong) UITableView *infoTableView; @end @implementation YMEditProfileInfoView - (void)ym_setupViews{ [self addSubview:self.infoTableView]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.infoTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(10)); make.left.equalTo(self); make.right.equalTo(self); make.bottom.equalTo(self).offset(adapt(-10)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMEditProfileViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; @weakify(self) [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) { @strongify(self) [self.infoTableView reloadData]; [self.infoTableView layoutIfNeeded]; //刷新高度 CGFloat infoTableViewHeight = self.infoTableView.contentSize.height; [self.infoTableView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(infoTableViewHeight); }]; }]; } #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.viewModel.infoDataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YMEditProfileInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMEditProfileInfoCell class])]; if (!cell) { cell = [[YMEditProfileInfoCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMEditProfileInfoCell class])]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell ym_bindViewModel:self.viewModel.infoDataArray[indexPath.row]]; return cell; } #pragma mark - UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return adapt(50); } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return CGFLOAT_MIN; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return CGFLOAT_MIN; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [self.viewModel.editProfileOperationSubject sendNext:@(self.viewModel.infoDataArray[indexPath.item].editProfileType)]; } - (UITableView *)infoTableView { if (!_infoTableView) { _infoTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; _infoTableView.delegate = self; _infoTableView.dataSource = self; _infoTableView.estimatedRowHeight = 0; _infoTableView.estimatedSectionHeaderHeight = 0; _infoTableView.estimatedSectionFooterHeight = 0; _infoTableView.showsVerticalScrollIndicator = NO; _infoTableView.showsHorizontalScrollIndicator = NO; _infoTableView.separatorColor = UIColor.clearColor; _infoTableView.backgroundColor = UIColor.whiteColor; [_infoTableView registerClass:[YMEditProfileInfoCell class] forCellReuseIdentifier:NSStringFromClass([YMEditProfileInfoCell class])]; } return _infoTableView; } @end