// // YMSettingViewController.m // MSYOUPAI // // Created by YoMi on 2024/2/21. // Copyright © 2024 MS. All rights reserved. // #import "YMSettingViewController.h" #import "YMSettingViewModel.h" #import "YMSettingCell.h" @interface YMSettingViewController() /// 设置VM @property (nonatomic, strong) YMSettingViewModel *viewModel; /// 内容列表 @property (nonatomic, strong) UITableView *contentTableView; /// 退出登录 @property (nonatomic, strong) UIButton *logOutBtn; @end @implementation YMSettingViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; } - (void)ym_setupViews{ [self.view addSubview:self.contentTableView]; [self.view addSubview:self.logOutBtn]; [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints{ [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(kYMNavHeight); make.left.equalTo(self.view); make.right.equalTo(self.view); }]; [self.logOutBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentTableView.mas_bottom).offset(adapt(10)); make.left.equalTo(self.view); make.right.equalTo(self.view); make.bottom.equalTo(self.view).offset(Is_iPhoneX ? adapt(-32) : adapt(-12)); }]; [super updateViewConstraints]; } - (void)ym_bindViewModel{ [self.viewModel getSettingListData]; @weakify(self) [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) { @strongify(self) [self.contentTableView reloadData]; }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.viewModel.listDataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YMSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMSettingCell class])]; if (!cell) { cell = [[YMSettingCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMSettingCell class])]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return adapt(50); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.viewModel.settingFunctionsOperationSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].settingFunctionsType)]; } - (UITableView *)contentTableView{ if (!_contentTableView) { _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; _contentTableView.delegate = self; _contentTableView.dataSource = self; _contentTableView.estimatedRowHeight = 0; _contentTableView.estimatedSectionHeaderHeight = 0; _contentTableView.estimatedSectionFooterHeight = 0; _contentTableView.showsVerticalScrollIndicator = NO; _contentTableView.showsHorizontalScrollIndicator = NO; _contentTableView.separatorColor = UIColor.clearColor; _contentTableView.backgroundColor = UIColor.whiteColor; [_contentTableView registerClass:[YMSettingCell class] forCellReuseIdentifier:NSStringFromClass([YMSettingCell class])]; } return _contentTableView; } - (UIButton *)logOutBtn{ if (!_logOutBtn) { _logOutBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _logOutBtn.backgroundColor = HexColorFromRGB(0xFFFFFF); _logOutBtn.titleLabel.font = LCFont(15); [_logOutBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal]; [_logOutBtn setTitle:@"退出登录" forState:UIControlStateNormal]; WS(weakSelf) [[[_logOutBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel.settingFunctionsOperationSubject sendNext:@(YMSettingFunctionsTypeLogOut)]; }]; } return _logOutBtn; } @end