123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- //
- // GroupSquareVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/5/6.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "GroupSquareVC.h"
- #import "GroupSquareModel.h"
- #import "GroupSquareSubModel.h"
- #import "GroupSquareCell.h"
- #import "MyTDGroupView.h"
- #import "GroupSynopsisVC.h"
- @interface GroupSquareVC ()<UITableViewDelegate,UITableViewDataSource>
- @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.leftTable.showsHorizontalScrollIndicator = NO;
- self.leftTable.showsVerticalScrollIndicator = NO;
- self.rightTable.delegate = self;
- self.rightTable.dataSource = self;
- 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 getData];
- }
- - (void)getData
- {
- WS(weakSelf);
- [self.leftArray removeAllObjects];
- NSString * url = [NSString stringWithFormat:@"%@%@",Host(API_APP_GROUP_Group_Category),@"0"];
- [[HttpManager sharedHttpManager] GET:url parameters:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSLog(@"%@",responseObject);
- if ([responseObject isKindOfClass:[NSArray class]]) {
- NSArray * array = responseObject;
- for (NSInteger i = 0; i < array.count; i ++) {
- GroupSquareModel * model = [GroupSquareModel modelWithDictionary:array[i]];
- model.isSelect = i == 0 ? YES : NO;
- [weakSelf.leftArray addObject:model];
- }
- GroupSquareModel * fmodel = weakSelf.leftArray.firstObject;
- [weakSelf getSubData:fmodel.Id];
- }
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-
- }];
- }
- - (void)getSubData:(NSInteger)listID
- {
- WS(weakSelf);
- [self.rightArray removeAllObjects];
- NSString * url = [NSString stringWithFormat:@"%@%ld",Host(API_APP_GROUP_Category_list),listID];
- [[HttpManager sharedHttpManager] GET:url parameters:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSArray * array = responseObject;
- NSLog(@"====== %ld",array.count);
- for (NSInteger i = 0; i < array.count; i ++) {
- GroupSquareSubModel * model = [GroupSquareSubModel modelWithDictionary:array[i]];
- [weakSelf.rightArray addObject:model];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf reloadData];
- });
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-
- }];
- }
- - (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{
- GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
- GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath];
- [cell setRightDataSubModel: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 getSubData:model.Id];
- }
- }else{
- GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
- GroupSynopsisVC * vc = [GroupSynopsisVC initGroupSynopsisVC];
- vc.GroupId = model.Id;
- [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
|