123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //
- // 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()<UITableViewDataSource, UITableViewDelegate>
- /// 设置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
|