GroupSquareVC.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.edges.mas_offset(UIEdgeInsetsZero);
  31. }];
  32. [self.SearchView.button setAction:^{
  33. NSLog(@"SearchView.button");
  34. }];
  35. self.leftTable.delegate = self;
  36. self.leftTable.dataSource = self;
  37. self.rightTable.delegate = self;
  38. self.rightTable.dataSource = self;
  39. [self setData];
  40. self.leftTable.estimatedRowHeight = 0;
  41. self.leftTable.estimatedSectionHeaderHeight = 0;
  42. self.leftTable.estimatedSectionFooterHeight = 0;
  43. self.rightTable.estimatedRowHeight = 0;
  44. self.rightTable.estimatedSectionHeaderHeight = 0;
  45. self.rightTable.estimatedSectionFooterHeight = 0;
  46. [self reloadData];
  47. }
  48. - (void)setData
  49. {
  50. [self.leftArray removeAllObjects];
  51. [self.rightArray removeAllObjects];
  52. GroupSquareModel * model = [[GroupSquareModel alloc] init];
  53. model.Title = @"推荐";
  54. model.isSelect = YES;
  55. [self.leftArray addObject:model];
  56. GroupSquareModel * amodel = [[GroupSquareModel alloc] init];
  57. amodel.Title = @"本周热门";
  58. amodel.isSelect = NO;
  59. [self.leftArray addObject:amodel];
  60. GroupSquareModel * cmodel = [[GroupSquareModel alloc] init];
  61. cmodel.Title = @"阅读馆";
  62. cmodel.isSelect = NO;
  63. [self.leftArray addObject:cmodel];
  64. GroupSquareModel * dmodel = [[GroupSquareModel alloc] init];
  65. dmodel.Title = @"人文自然";
  66. dmodel.isSelect = NO;
  67. [self.leftArray addObject:dmodel];
  68. GroupSquareModel * bmodel = [[GroupSquareModel alloc] init];
  69. bmodel.Title = @"中国历史研究组";
  70. bmodel.Des = @"研究中国上下五千年的文化精粹化精粹";
  71. [self.rightArray addObject:bmodel];
  72. [self.rightArray addObject:bmodel];
  73. [self.rightArray addObject:bmodel];
  74. [self.rightArray addObject:bmodel];
  75. }
  76. - (void)reloadData
  77. {
  78. [self.leftTable reloadData];
  79. [self.rightTable reloadData];
  80. }
  81. #pragma mark -UITableViewDelegate
  82. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  83. {
  84. if (tableView == self.leftTable) {
  85. return self.leftArray.count;
  86. }else{
  87. return self.rightArray.count;
  88. }
  89. }
  90. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  91. {
  92. if (tableView == self.leftTable) {
  93. return [GroupSquareCell configCell0Height];
  94. }else{
  95. return [GroupSquareCell configCell1Height];
  96. }
  97. }
  98. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  99. {
  100. if (tableView == self.leftTable) {
  101. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  102. GroupSquareCell * cell = [GroupSquareCell configCell0:tableView indexPath:indexPath];
  103. [cell setLeftDataModel:model];
  104. return cell;
  105. }else{
  106. GroupSquareModel * model = [self.rightArray objectAtIndex:indexPath.row];
  107. GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath];
  108. [cell setRightDataModel:model];
  109. return cell;
  110. }
  111. }
  112. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  115. if (tableView == self.leftTable) {
  116. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  117. if (!model.isSelect) {
  118. [self.leftArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  119. GroupSquareModel * smodel = (GroupSquareModel *)obj;
  120. smodel.isSelect = NO;
  121. }];
  122. model.isSelect = !model.isSelect;
  123. [self reloadData];
  124. }
  125. }
  126. }
  127. #pragma mark - Load On Demand
  128. - (NSMutableArray *)leftArray
  129. {
  130. if (!_leftArray) {
  131. _leftArray = [NSMutableArray array];
  132. }
  133. return _leftArray;
  134. }
  135. - (NSMutableArray *)rightArray
  136. {
  137. if (!_rightArray) {
  138. _rightArray = [NSMutableArray array];
  139. }
  140. return _rightArray;
  141. }
  142. - (MyTDGroupView *)SearchView
  143. {
  144. if (!_SearchView) {
  145. _SearchView = [[MyTDGroupView alloc] init];
  146. }
  147. return _SearchView;
  148. }
  149. @end