// // GroupSquareVC.m // smartRhino // // Created by niuzhen on 2020/5/6. // Copyright © 2020 tederen. All rights reserved. // #import "GroupSquareVC.h" #import "GroupSquareModel.h" #import "GroupSquareCell.h" #import "MyTDGroupView.h" #import "GroupSynopsisVC.h" @interface GroupSquareVC () @property (weak, nonatomic) IBOutlet UITableView *leftTable; @property (weak, nonatomic) IBOutlet UITableView *rightTable; @property (weak, nonatomic) IBOutlet UIView *HeadView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *height; @property (strong, nonatomic) MyTDGroupView *SearchView; @property (copy, nonatomic) NSMutableArray *leftArray; @property (copy, nonatomic) NSMutableArray *rightArray; @end @implementation GroupSquareVC +(GroupSquareVC *)initGroupSquareVC{ GroupSquareVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSquareVC"]; return controller; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; [self.HeadView addSubview:self.SearchView]; [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(6); make.left.right.mas_equalTo(self.HeadView); make.height.mas_offset(36); }]; [self.SearchView.button setAction:^{ NSLog(@"SearchView.button"); }]; self.leftTable.delegate = self; self.leftTable.dataSource = self; self.rightTable.delegate = self; self.rightTable.dataSource = self; [self setData]; self.leftTable.estimatedRowHeight = 0; self.leftTable.estimatedSectionHeaderHeight = 0; self.leftTable.estimatedSectionFooterHeight = 0; self.rightTable.estimatedRowHeight = 0; self.rightTable.estimatedSectionHeaderHeight = 0; self.rightTable.estimatedSectionFooterHeight = 0; [self reloadData]; } - (void)setData { [self.leftArray removeAllObjects]; [self.rightArray removeAllObjects]; GroupSquareModel * model = [[GroupSquareModel alloc] init]; model.Title = @"推荐"; model.isSelect = YES; [self.leftArray addObject:model]; GroupSquareModel * amodel = [[GroupSquareModel alloc] init]; amodel.Title = @"本周热门"; amodel.isSelect = NO; [self.leftArray addObject:amodel]; GroupSquareModel * cmodel = [[GroupSquareModel alloc] init]; cmodel.Title = @"阅读馆"; cmodel.isSelect = NO; [self.leftArray addObject:cmodel]; GroupSquareModel * dmodel = [[GroupSquareModel alloc] init]; dmodel.Title = @"人文自然"; dmodel.isSelect = NO; [self.leftArray addObject:dmodel]; GroupSquareModel * bmodel = [[GroupSquareModel alloc] init]; bmodel.Title = @"中国历史研究组"; bmodel.Des = @"研究中国上下五千年的文化精粹化精粹"; [self.rightArray addObject:bmodel]; [self.rightArray addObject:bmodel]; [self.rightArray addObject:bmodel]; [self.rightArray addObject:bmodel]; } - (void)reloadData { [self.leftTable reloadData]; [self.rightTable reloadData]; } #pragma mark -UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.leftTable) { return self.leftArray.count; }else{ return self.rightArray.count; } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == self.leftTable) { return [GroupSquareCell configCell0Height]; }else{ return [GroupSquareCell configCell1Height]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == self.leftTable) { GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row]; GroupSquareCell * cell = [GroupSquareCell configCell0:tableView indexPath:indexPath]; [cell setLeftDataModel:model]; return cell; }else{ GroupSquareModel * model = [self.rightArray objectAtIndex:indexPath.row]; GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath]; [cell setRightDataModel:model]; return cell; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (tableView == self.leftTable) { GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row]; if (!model.isSelect) { [self.leftArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { GroupSquareModel * smodel = (GroupSquareModel *)obj; smodel.isSelect = NO; }]; model.isSelect = !model.isSelect; if (indexPath.row == 0) { self.height.constant = 0.f; }else{ self.height.constant = 19.f; } [self reloadData]; } }else{ GroupSynopsisVC * vc = [GroupSynopsisVC initGroupSynopsisVC]; [self.navigationController pushViewController:vc animated:YES]; } } #pragma mark - Load On Demand - (NSMutableArray *)leftArray { if (!_leftArray) { _leftArray = [NSMutableArray array]; } return _leftArray; } - (NSMutableArray *)rightArray { if (!_rightArray) { _rightArray = [NSMutableArray array]; } return _rightArray; } - (MyTDGroupView *)SearchView { if (!_SearchView) { _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)]; } return _SearchView; } @end