// // HomeDayGoodArticeVC.m // smartRhino // // Created by niuzhen on 2020/6/23. // Copyright © 2020 tederen. All rights reserved. // #import "HomeDayGoodArticeVC.h" #import "HomeSubModel.h" #import "HomeSubItemModel.h" #import "BookSubArticeCell.h" @interface HomeDayGoodArticeVC () @property (nonatomic, strong) UITableView * tableView; @property (nonatomic, strong) NSMutableArray * dataSource; @property (nonatomic, assign) NSInteger currentPage; @property (nonatomic, assign) NSInteger Total; @end @implementation HomeDayGoodArticeVC - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.tableView]; self.tableView.delegate = self; self.tableView.dataSource = self; self.currentPage = 1; self.Total = 0; WS(weakSelf); self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ [weakSelf footerRefresh]; }]; [self headRefresh]; } - (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)headRefresh{ self.currentPage = 1; self.Total = 1; [self.dataSource removeAllObjects]; [self getData]; } - (void)footerRefresh{ self.currentPage += 1; if (self.Total == self.dataSource.count) { self.currentPage --; [self.tableView.mj_footer endRefreshingWithNoMoreData]; self.tableView.mj_footer.hidden = YES; return ; } [self getData]; } - (void)getData { WS(weakSelf); [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_GooDText) parameters:@{@"StyleCss":self.style,@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) { NSLog(@"%@",responseObject); [weakSelf.tableView.mj_footer endRefreshing]; if ([responseObject isKindOfClass:[NSDictionary class]]) { HomeSubModel *model = [HomeSubModel modelWithDictionary:responseObject]; for (NSDictionary * dict in model.Items) { HomeSubItemModel *smodel = [HomeSubItemModel modelWithDictionary:dict]; [weakSelf.dataSource addObject:smodel]; } weakSelf.Total = model.Total; if (weakSelf.Total == weakSelf.dataSource.count) { [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData]; weakSelf.tableView.mj_footer.hidden = YES; } } dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { [weakSelf.tableView.mj_footer endRefreshing]; }]; } - (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]; BookSubArticeCell * cell = [BookSubArticeCell configCell:tableView indexPath:indexPath]; [cell setDataWithModel:model]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; HomeSubItemModel *model = self.dataSource[indexPath.row]; MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.Id = model.Id; vc.type = model.MediaType; [self.navigationController pushViewController:vc animated:YES]; } @end