YMSearchUserViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // YMSearchUserViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/17.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMSearchUserViewController.h"
  9. #import "YMSearchUserViewModel.h"
  10. #import "YMSearchUserSearchInputBoxView.h"
  11. #import "YMSearchUserCell.h"
  12. @interface YMSearchUserViewController()<UITableViewDataSource, UITableViewDelegate>
  13. /// 搜索用户VM
  14. @property (nonatomic, strong) YMSearchUserViewModel *viewModel;
  15. /// 搜索输入框视图
  16. @property (nonatomic, strong) YMSearchUserSearchInputBoxView *searchInputBoxView;
  17. /// 内容列表
  18. @property (nonatomic, strong) UITableView *contentTableView;
  19. @end
  20. @implementation YMSearchUserViewController
  21. @dynamic viewModel;
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self setNavHidden:YES];
  25. }
  26. - (void)ym_setupViews{
  27. [self.view addSubview:self.searchInputBoxView];
  28. [self.view addSubview:self.contentTableView];
  29. [self.view setNeedsUpdateConstraints];
  30. [self.view updateConstraintsIfNeeded];
  31. }
  32. - (void)updateViewConstraints{
  33. [self.searchInputBoxView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.equalTo(self.view);
  35. make.left.equalTo(self.view);
  36. make.right.equalTo(self.view);
  37. }];
  38. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.equalTo(self.searchInputBoxView.mas_bottom);
  40. make.left.equalTo(self.view);
  41. make.right.equalTo(self.view);
  42. make.bottom.equalTo(self.view);
  43. }];
  44. [super updateViewConstraints];
  45. }
  46. - (void)ym_bindViewModel{
  47. [self.searchInputBoxView ym_bindViewModel:self.viewModel];
  48. @weakify(self)
  49. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  50. @strongify(self)
  51. [self.contentTableView reloadData];
  52. [self.contentTableView ym_endLoading];
  53. }];
  54. }
  55. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  56. return self.viewModel.listDataArray.count;
  57. }
  58. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  59. YMSearchUserCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMSearchUserCell class])];
  60. if (!cell) {
  61. cell = [[YMSearchUserCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMSearchUserCell class])];
  62. }
  63. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  64. [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]];
  65. return cell;
  66. }
  67. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  68. return adapt(85);
  69. }
  70. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  71. if (self.viewModel.listDataArray[indexPath.item].userId != 0) {
  72. [self.viewModel.gotoPersonalPageSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].userId)];
  73. }
  74. }
  75. - (YMSearchUserSearchInputBoxView *)searchInputBoxView{
  76. if (!_searchInputBoxView) {
  77. _searchInputBoxView = [[YMSearchUserSearchInputBoxView alloc]init];
  78. }
  79. return _searchInputBoxView;
  80. }
  81. - (UITableView *)contentTableView{
  82. if (!_contentTableView) {
  83. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  84. _contentTableView.delegate = self;
  85. _contentTableView.dataSource = self;
  86. _contentTableView.estimatedRowHeight = 0;
  87. _contentTableView.estimatedSectionHeaderHeight = 0;
  88. _contentTableView.estimatedSectionFooterHeight = 0;
  89. _contentTableView.showsVerticalScrollIndicator = NO;
  90. _contentTableView.showsHorizontalScrollIndicator = NO;
  91. _contentTableView.separatorColor = UIColor.clearColor;
  92. _contentTableView.backgroundColor = UIColor.whiteColor;
  93. [_contentTableView registerClass:[YMSearchUserCell class] forCellReuseIdentifier:NSStringFromClass([YMSearchUserCell class])];
  94. YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
  95. empty.imageSize = kEmptyViewSize;
  96. _contentTableView.ym_emptyView = empty;
  97. _contentTableView.ym_emptyView.autoShowEmptyView = YES;
  98. }
  99. return _contentTableView;
  100. }
  101. @end