// // ReportListVC.m // LNManager // // Created by EchoShacolee on 2017/5/31. // Copyright © 2017年 lee. All rights reserved. // //废弃 #import "ReportListVC.h" #import "RepListCell.h" #import "MJRefresh.h" #import "NSArray+ex.h" #import "NSString+ex.h" @interface ReportListVC () { //记录页书 NSInteger _currentPageNum; //加载数据的类型 MyGetDataType _getDataType; //缓存高度 NSMutableArray * _heightArr; } @end @implementation ReportListVC - (void)viewDidLoad { [super viewDidLoad]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _currentPageNum = 0; _getDataType = MyGetDataTypeNomal; [self setRefreshAction];//设置刷新 [self getData]; __weak typeof(self) weakSelf = self; self.block = ^{ _currentPageNum = 0; [weakSelf getData]; }; } #pragma mark - 下拉刷新,上拉加载 - -(void)setRefreshAction{ // 下拉加载更多 __weak typeof(self) weakSelf = self; MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [weakSelf headerRefresh]; }]; self.tableView.mj_header = header; MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ [weakSelf footerRefresh]; }]; self.tableView.mj_footer = footer; } -(void)headerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeHeaderRefresh; //加载数据 [self getData]; [self.tableView.mj_header endRefreshing]; } -(void)footerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeFooterRefresh; //加载数据 [self getData]; [self.tableView.mj_footer endRefreshing]; } -(void)getData{ //判断当前是否正在加载数据。如果正在加载数据,直接return。 if (_IS_LOADING) { return; } _IS_LOADING=YES; //获取第一页数据 NSInteger needLoadPage; needLoadPage=_currentPageNum+1; if (_getDataType==MyGetDataTypeHeaderRefresh) { needLoadPage=1; } NSMutableDictionary * mDic = [NSMutableDictionary new]; [mDic setObject:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"]; [mDic setObject:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"]; [mDic setObject:@"1" forKey:@"isPage"]; [mDic setObject:@"10" forKey:@"pageSize"]; [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"]; __weak typeof(self) weakSelf = self; [self getDataWithDic:mDic method:@"getReports" block:^(NSDictionary *successDic) { //处理数据 //如果获取到了数据,而且是下拉刷新,清空数组。 if (_getDataType==MyGetDataTypeHeaderRefresh){ [weakSelf.dataurce removeAllObjects]; } //追加数据 [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]]; if (weakSelf.dataurce.count != 0) { weakSelf.holderV.hidden = YES; } //计数器+1 _currentPageNum=needLoadPage; //刷新界面 [weakSelf.tableView reloadData]; //恢复初始状态。 _getDataType=MyGetDataTypeNomal; }]; } #pragma mark tableView代理方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataurce.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ RepListCell * cell = [RepListCell cellForTabelView:tableView]; [cell updateWithDic:self.dataurce[indexPath.row]]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ //缓存高度 NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row]; if (cellHeight) { return [cellHeight floatValue]; }else{ CGFloat h1 = 0; NSDictionary * dic = self.dataurce[indexPath.row]; if ([dic[@"content"] length] != 0) { CGFloat w = self.tableView.frame.size.width-40; NSString *str = [NSString stringWithFormat:@"举报内容 :%@",dic[@"content"]]; h1 = [str heightForWid:w Font:14] + 5; } CGFloat H = 97+h1;//67为其它固定高度 [_heightArr addObject:@(H)]; return H; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end