// // TFPopularityCommViewController.m // TFReader // // Created by 谢腾飞 on 2020/12/17. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFPopularityCommViewController.h" #import "TFPopularityDetailViewController.h" #import "TFPopularityViewCell.h" #import "TFPopularityModel.h" @interface TFPopularityCommViewController () @end @implementation TFPopularityCommViewController - (void)viewDidLoad { [super viewDidLoad]; [self initialize]; [self createSubviews]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self setStatusBarDefaultStyle]; } - (void)initialize { [self hiddenNavigationBar:YES]; } - (void)createSubviews { self.mainTableView.delegate = self; self.mainTableView.dataSource = self; self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0); [self.view addSubview:self.mainTableView]; [self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(self.view.mas_top); make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_NAVBAR_HEIGHT - self.pageViewHeight); make.width.mas_equalTo(self.view.mas_width); }]; [self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") buttonTitle:@"" tapBlock:^{ }]; WS(weakSelf) self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{ [weakSelf netRequest]; }]; [self.mainTableView.mj_header beginRefreshing]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataSourceArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TFPopularityViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WXBookRankListTableViewCell"]; if (!cell) { cell = [[TFPopularityViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WXBookRankListTableViewCell"]; } if (self.dataSourceArray.count) { cell.rankListModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row]; } cell.productionType = self.productionType; cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1); cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return CGFLOAT_MIN; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)]; view.backgroundColor = [UIColor clearColor]; return view; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return CGFLOAT_MIN; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET)]; view.backgroundColor = [UIColor clearColor]; return view; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.dataSourceArray && self.dataSourceArray.count > 0) { TFPopularityModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row]; TFPopularityDetailViewController *vc = [[TFPopularityDetailViewController alloc] init]; vc.channel = self.channel; vc.productionType = self.productionType; vc.rank_type = t_model.rank_type; vc.navTitle = t_model.list_name?:@""; [self.navigationController pushViewController:vc animated:YES]; } } - (void)netRequest { NSString *url = @""; switch (self.productionType) { case TFProductionTypeNovel: url = Book_Rank_List; break; case TFProductionTypeComic: url = Comic_Rank_List; break; case TFProductionTypeAudio: url = Audio_Rank_List; break; default: break; } WS(weakSelf) NSMutableDictionary *params = [NSMutableDictionary dictionary]; params[@"channel_id"] = self.channel; [TFNetworkTools POST:url parameters:params model:nil success:^(BOOL isSuccess, NSDictionary *_Nullable t_model, TFNetworkRequestModel *requestModel) { [weakSelf.mainTableView endRefreshing]; if (isSuccess) { NSArray *t_arr = t_model[@"data"]; [weakSelf.dataSourceArray removeAllObjects]; for (NSDictionary *t_dic in t_arr) { TFPopularityModel *t_model = [TFPopularityModel modelWithDictionary:t_dic]; [weakSelf.dataSourceArray addObject:t_model]; } } [weakSelf.mainTableView reloadData]; [weakSelf.mainTableView xtfei_endLoading]; } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { [weakSelf.mainTableView endRefreshing]; [weakSelf.mainTableView reloadData]; [weakSelf.mainTableView xtfei_endLoading]; }]; } @end