// // HomeSchoolVC.m // smartRhino // // Created by niuzhen on 2020/6/23. // Copyright © 2020 tederen. All rights reserved. // #import "HomeSchoolVC.h" #import "HomeSubItemModel.h" #import "HomeSchoolCell.h" #import "HomeSCDetailVC.h" @interface HomeSchoolVC () @property (nonatomic, strong) UITableView * tableView; @property (nonatomic, strong) NSMutableArray * dataSource; @end @implementation HomeSchoolVC - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.tableView]; self.tableView.delegate = self; self.tableView.dataSource = self; [self getData]; } - (void)setHeight:(CGFloat)height { [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.showsVerticalScrollIndicator = NO; } return _tableView; } - (NSMutableArray *)dataSource { if (!_dataSource) { _dataSource = [NSMutableArray array]; } return _dataSource; } - (void)getData { WS(weakSelf); [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_Press) parameters:@{@"Page":@(1),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) { NSLog(@"%@",responseObject); if ([responseObject isKindOfClass:[NSDictionary class]]) { for (NSDictionary * dict in responseObject[@"Items"]) { HomeSubItemModel *model = [HomeSubItemModel modelWithDictionary:dict]; [weakSelf.dataSource addObject:model]; } } dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataSource.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HomeSubItemModel *model = self.dataSource[indexPath.row]; HomeSchoolCell * cell = [HomeSchoolCell configCell0:tableView indexPath:indexPath]; if (indexPath.row > 0) { cell.topView.hidden = YES; cell.height.constant = 0.f; } cell.lineV.hidden = NO; [cell setDataModel:model]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { HomeSubItemModel *model = self.dataSource[indexPath.row]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init]; vc.Id = model.Id; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; } @end