YMEditProfileInfoView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // YMEditProfileInfoView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/18.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMEditProfileInfoView.h"
  9. #import "YMEditProfileViewModel.h"
  10. #import "YMEditProfileInfoCell.h"
  11. @interface YMEditProfileInfoView ()<UITableViewDelegate, UITableViewDataSource>
  12. /// 编辑资料VM
  13. @property (nonatomic, strong) YMEditProfileViewModel *viewModel;
  14. /// 信息列表
  15. @property (nonatomic, strong) UITableView *infoTableView;
  16. @end
  17. @implementation YMEditProfileInfoView
  18. - (void)ym_setupViews{
  19. [self addSubview:self.infoTableView];
  20. [self setNeedsUpdateConstraints];
  21. [self updateConstraintsIfNeeded];
  22. }
  23. - (void)updateConstraints{
  24. [self.infoTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.top.equalTo(self).offset(adapt(10));
  26. make.left.equalTo(self);
  27. make.right.equalTo(self);
  28. make.bottom.equalTo(self).offset(adapt(-10));
  29. }];
  30. [super updateConstraints];
  31. }
  32. - (void)ym_bindViewModel:(YMEditProfileViewModel *)viewModel{
  33. if (!viewModel) {
  34. return;
  35. }
  36. _viewModel = viewModel;
  37. @weakify(self)
  38. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  39. @strongify(self)
  40. [self.infoTableView reloadData];
  41. [self.infoTableView layoutIfNeeded];
  42. //刷新高度
  43. CGFloat infoTableViewHeight = self.infoTableView.contentSize.height;
  44. [self.infoTableView mas_updateConstraints:^(MASConstraintMaker *make) {
  45. make.height.mas_equalTo(infoTableViewHeight);
  46. }];
  47. }];
  48. }
  49. #pragma mark - UITableViewDataSource
  50. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  51. return 1;
  52. }
  53. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  54. return self.viewModel.infoDataArray.count;
  55. }
  56. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  57. YMEditProfileInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMEditProfileInfoCell class])];
  58. if (!cell) {
  59. cell = [[YMEditProfileInfoCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMEditProfileInfoCell class])];
  60. }
  61. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  62. [cell ym_bindViewModel:self.viewModel.infoDataArray[indexPath.row]];
  63. return cell;
  64. }
  65. #pragma mark - UITableViewDelegate
  66. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  67. return adapt(50);
  68. }
  69. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  70. return nil;
  71. }
  72. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  73. return CGFLOAT_MIN;
  74. }
  75. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  76. return nil;
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  79. return CGFLOAT_MIN;
  80. }
  81. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  82. [self.viewModel.editProfileOperationSubject sendNext:@(self.viewModel.infoDataArray[indexPath.item].editProfileType)];
  83. }
  84. - (UITableView *)infoTableView {
  85. if (!_infoTableView) {
  86. _infoTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  87. _infoTableView.delegate = self;
  88. _infoTableView.dataSource = self;
  89. _infoTableView.estimatedRowHeight = 0;
  90. _infoTableView.estimatedSectionHeaderHeight = 0;
  91. _infoTableView.estimatedSectionFooterHeight = 0;
  92. _infoTableView.showsVerticalScrollIndicator = NO;
  93. _infoTableView.showsHorizontalScrollIndicator = NO;
  94. _infoTableView.separatorColor = UIColor.clearColor;
  95. _infoTableView.backgroundColor = UIColor.whiteColor;
  96. [_infoTableView registerClass:[YMEditProfileInfoCell class] forCellReuseIdentifier:NSStringFromClass([YMEditProfileInfoCell class])];
  97. }
  98. return _infoTableView;
  99. }
  100. @end