123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // 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 ()<UITableViewDelegate, UITableViewDataSource>
- /// 编辑资料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
|