GroupSquareVC.m 5.0 KB

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