YMSettingViewController.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // YMSettingViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMSettingViewController.h"
  9. #import "YMSettingViewModel.h"
  10. #import "YMSettingCell.h"
  11. @interface YMSettingViewController()<UITableViewDataSource, UITableViewDelegate>
  12. /// 设置VM
  13. @property (nonatomic, strong) YMSettingViewModel *viewModel;
  14. /// 内容列表
  15. @property (nonatomic, strong) UITableView *contentTableView;
  16. /// 退出登录
  17. @property (nonatomic, strong) UIButton *logOutBtn;
  18. @end
  19. @implementation YMSettingViewController
  20. @dynamic viewModel;
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. }
  24. - (void)ym_setupViews{
  25. [self.view addSubview:self.contentTableView];
  26. [self.view addSubview:self.logOutBtn];
  27. [self.view setNeedsUpdateConstraints];
  28. [self.view updateConstraintsIfNeeded];
  29. }
  30. - (void)updateViewConstraints{
  31. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.equalTo(self.view).offset(kYMNavHeight);
  33. make.left.equalTo(self.view);
  34. make.right.equalTo(self.view);
  35. }];
  36. [self.logOutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(self.contentTableView.mas_bottom).offset(adapt(10));
  38. make.left.equalTo(self.view);
  39. make.right.equalTo(self.view);
  40. make.bottom.equalTo(self.view).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  41. }];
  42. [super updateViewConstraints];
  43. }
  44. - (void)ym_bindViewModel{
  45. [self.viewModel getSettingListData];
  46. @weakify(self)
  47. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  48. @strongify(self)
  49. [self.contentTableView reloadData];
  50. }];
  51. }
  52. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  53. return self.viewModel.listDataArray.count;
  54. }
  55. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  56. YMSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMSettingCell class])];
  57. if (!cell) {
  58. cell = [[YMSettingCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMSettingCell class])];
  59. }
  60. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  61. [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]];
  62. return cell;
  63. }
  64. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  65. return adapt(50);
  66. }
  67. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  68. [self.viewModel.settingFunctionsOperationSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].settingFunctionsType)];
  69. }
  70. - (UITableView *)contentTableView{
  71. if (!_contentTableView) {
  72. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  73. _contentTableView.delegate = self;
  74. _contentTableView.dataSource = self;
  75. _contentTableView.estimatedRowHeight = 0;
  76. _contentTableView.estimatedSectionHeaderHeight = 0;
  77. _contentTableView.estimatedSectionFooterHeight = 0;
  78. _contentTableView.showsVerticalScrollIndicator = NO;
  79. _contentTableView.showsHorizontalScrollIndicator = NO;
  80. _contentTableView.separatorColor = UIColor.clearColor;
  81. _contentTableView.backgroundColor = UIColor.whiteColor;
  82. [_contentTableView registerClass:[YMSettingCell class] forCellReuseIdentifier:NSStringFromClass([YMSettingCell class])];
  83. }
  84. return _contentTableView;
  85. }
  86. - (UIButton *)logOutBtn{
  87. if (!_logOutBtn) {
  88. _logOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  89. _logOutBtn.backgroundColor = HexColorFromRGB(0xFFFFFF);
  90. _logOutBtn.titleLabel.font = LCFont(15);
  91. [_logOutBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
  92. [_logOutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
  93. WS(weakSelf)
  94. [[[_logOutBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  95. [weakSelf.viewModel.settingFunctionsOperationSubject sendNext:@(YMSettingFunctionsTypeLogOut)];
  96. }];
  97. }
  98. return _logOutBtn;
  99. }
  100. @end