GroupSquareVC.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // GroupSquareVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/6.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "GroupSquareVC.h"
  9. #import "GroupSquareModel.h"
  10. #import "GroupSquareCell.h"
  11. #import "MyTDGroupView.h"
  12. @interface GroupSquareVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (weak, nonatomic) IBOutlet UITableView *leftTable;
  14. @property (weak, nonatomic) IBOutlet UITableView *rightTable;
  15. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  16. @property (strong, nonatomic) MyTDGroupView *SearchView;
  17. @property (copy, nonatomic) NSMutableArray *leftArray;
  18. @property (copy, nonatomic) NSMutableArray *rightArray;
  19. @end
  20. @implementation GroupSquareVC
  21. +(GroupSquareVC *)initGroupSquareVC{
  22. GroupSquareVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSquareVC"];
  23. return controller;
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.fd_prefersNavigationBarHidden = YES;
  28. [self.HeadView addSubview:self.SearchView];
  29. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.top.mas_offset(6);
  31. make.left.right.mas_equalTo(self.HeadView);
  32. make.height.mas_offset(36);
  33. }];
  34. [self.SearchView.button setAction:^{
  35. NSLog(@"SearchView.button");
  36. }];
  37. self.leftTable.delegate = self;
  38. self.leftTable.dataSource = self;
  39. self.rightTable.delegate = self;
  40. self.rightTable.dataSource = self;
  41. [self setData];
  42. self.leftTable.estimatedRowHeight = 0;
  43. self.leftTable.estimatedSectionHeaderHeight = 0;
  44. self.leftTable.estimatedSectionFooterHeight = 0;
  45. self.rightTable.estimatedRowHeight = 0;
  46. self.rightTable.estimatedSectionHeaderHeight = 0;
  47. self.rightTable.estimatedSectionFooterHeight = 0;
  48. [self reloadData];
  49. }
  50. - (void)setData
  51. {
  52. [self.leftArray removeAllObjects];
  53. [self.rightArray removeAllObjects];
  54. GroupSquareModel * model = [[GroupSquareModel alloc] init];
  55. model.Title = @"推荐";
  56. model.isSelect = YES;
  57. [self.leftArray addObject:model];
  58. GroupSquareModel * amodel = [[GroupSquareModel alloc] init];
  59. amodel.Title = @"本周热门";
  60. amodel.isSelect = NO;
  61. [self.leftArray addObject:amodel];
  62. GroupSquareModel * cmodel = [[GroupSquareModel alloc] init];
  63. cmodel.Title = @"阅读馆";
  64. cmodel.isSelect = NO;
  65. [self.leftArray addObject:cmodel];
  66. GroupSquareModel * dmodel = [[GroupSquareModel alloc] init];
  67. dmodel.Title = @"人文自然";
  68. dmodel.isSelect = NO;
  69. [self.leftArray addObject:dmodel];
  70. GroupSquareModel * bmodel = [[GroupSquareModel alloc] init];
  71. bmodel.Title = @"中国历史研究组";
  72. bmodel.Des = @"研究中国上下五千年的文化精粹化精粹";
  73. [self.rightArray addObject:bmodel];
  74. [self.rightArray addObject:bmodel];
  75. [self.rightArray addObject:bmodel];
  76. [self.rightArray addObject:bmodel];
  77. }
  78. - (void)reloadData
  79. {
  80. [self.leftTable reloadData];
  81. [self.rightTable reloadData];
  82. }
  83. #pragma mark -UITableViewDelegate
  84. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  85. {
  86. if (tableView == self.leftTable) {
  87. return self.leftArray.count;
  88. }else{
  89. return self.rightArray.count;
  90. }
  91. }
  92. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  93. {
  94. if (tableView == self.leftTable) {
  95. return [GroupSquareCell configCell0Height];
  96. }else{
  97. return [GroupSquareCell configCell1Height];
  98. }
  99. }
  100. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  101. {
  102. if (tableView == self.leftTable) {
  103. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  104. GroupSquareCell * cell = [GroupSquareCell configCell0:tableView indexPath:indexPath];
  105. [cell setLeftDataModel:model];
  106. return cell;
  107. }else{
  108. GroupSquareModel * model = [self.rightArray objectAtIndex:indexPath.row];
  109. GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath];
  110. [cell setRightDataModel:model];
  111. return cell;
  112. }
  113. }
  114. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  115. {
  116. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  117. if (tableView == self.leftTable) {
  118. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  119. if (!model.isSelect) {
  120. [self.leftArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  121. GroupSquareModel * smodel = (GroupSquareModel *)obj;
  122. smodel.isSelect = NO;
  123. }];
  124. model.isSelect = !model.isSelect;
  125. [self reloadData];
  126. }
  127. }
  128. }
  129. #pragma mark - Load On Demand
  130. - (NSMutableArray *)leftArray
  131. {
  132. if (!_leftArray) {
  133. _leftArray = [NSMutableArray array];
  134. }
  135. return _leftArray;
  136. }
  137. - (NSMutableArray *)rightArray
  138. {
  139. if (!_rightArray) {
  140. _rightArray = [NSMutableArray array];
  141. }
  142. return _rightArray;
  143. }
  144. - (MyTDGroupView *)SearchView
  145. {
  146. if (!_SearchView) {
  147. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  148. }
  149. return _SearchView;
  150. }
  151. @end