123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- //
- // EAreasListVC
- // LN_School
- //
- // Created by EchoShacolee on 2017/6/16.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "EAreasListVC.h"
- #import "MJRefresh.h"
- #import "EAreasImagesShowVC.h"
- typedef NS_ENUM(NSInteger, MyGetDataType) {
- //正常请求数据
- MyGetDataTypeNomal=0,
- //下拉刷新请求数据
- MyGetDataTypeHeaderRefresh,
- //上拉加载更多请求数据
- MyGetDataTypeFooterRefresh
- };
- @interface EAreasListVC ()<UITableViewDataSource,UITableViewDelegate>
- {
- //记录页书
- NSInteger _currentPageNum;
- //正在加载的状态
- BOOL _IS_LOADING;
- //加载数据的类型
- MyGetDataType _getDataType;
- //
- HolderView *_holderV;
- //缓存cell高度
- NSMutableArray * _heightArr;
- }
- @property (nonatomic,retain)NSMutableArray * dataurce;
- @property(nonatomic,retain)UITableView *tableView;
- @end
- @implementation EAreasListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"电子围栏";
- self.view.backgroundColor = KBackGroundColor;
- self.navigationController.navigationBar.translucent = NO;
-
- _dataurce = [[NSMutableArray alloc]init];
- _currentPageNum = 0;
- _IS_LOADING = NO;
- _getDataType = MyGetDataTypeNomal;
-
- _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
- _tableView.backgroundColor = KBackGroundColor;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.sectionHeaderHeight = 20;
- _tableView.tableFooterView = [UIView new];
- [self.view addSubview:_tableView];
-
-
- [self goBackByNavigation];
- [self getData];
-
- _holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
- _holderV.y = kNavOffSet;
- [_holderV freshBlock:^{
- [self headerRefresh];
- }];
- [self.view addSubview:_holderV];
- }
- #pragma mark - 下拉刷新,上拉加载 -
- -(void)setRefreshAction{
-
- // 下拉刷新
-
- __weak typeof(self) weakSelf = self;
- MJRefreshGifHeader * header = [self.tableView addGifHeaderWithRefreshingBlock:^{
- [weakSelf headerRefresh];
- }];
- header.updatedTimeHidden = YES;
-
-
- MJRefreshFooter *foot = [self.tableView addGifFooterWithRefreshingBlock:^{
- [weakSelf footerRefresh];
- }];
- foot.automaticallyRefresh = YES;
-
- }
- #pragma mark - 数据加载更多和刷新 -
- -(void)headerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeHeaderRefresh;
- //加载数据
- [self getData];
- }
- -(void)footerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeFooterRefresh;
- //加载数据
- [self getData];
- }
- -(void)getData{
-
- //判断当前是否正在加载数据。如果正在加载数据,直接return。
- if (_IS_LOADING) {
- return;
- }
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- _IS_LOADING=YES;
- //获取第一页数据
- NSInteger needLoadPage;
- needLoadPage=_currentPageNum+1;
- if (_getDataType==MyGetDataTypeHeaderRefresh) {
- needLoadPage=1;
- }
-
- NSMutableDictionary * mDic = [NSMutableDictionary new];
- [mDic setObject:defUser.userDict[@"school"] forKey:@"jxbh"];
-
- // [mDic setObject:@"1" forKey:@"isPage"];
- // [mDic setObject:@"10" forKey:@"pageSize"];
- // [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
- __weak typeof(self) weakSelf = self;
-
- [NetManager requestAnythingWithURL:@"getAreas" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
-
- _holderV.hidden = YES;
- //设置加载状态
- _IS_LOADING=NO;
-
- if (!root) {
- ShowErrorMsg(@"请求失败!");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowErrorMsg(root[@"msg"]);
- return;
- }
-
-
- //如果是上拉加载更多,应该结束上拉刷新的界面。
- if (_getDataType==MyGetDataTypeFooterRefresh) {
- [weakSelf.tableView.gifFooter endRefreshing];
- }
- //如果是下拉刷新,应该结束界面刷新状态;
- else if (_getDataType==MyGetDataTypeHeaderRefresh){
-
- [weakSelf.tableView.gifHeader endRefreshing];
- }
- //处理数据
- //如果获取到了数据,而且是下拉刷新,清空数组。
- if (_getDataType==MyGetDataTypeHeaderRefresh){
- [weakSelf.dataurce removeAllObjects];
- }
- //追加数据
- [weakSelf.dataurce addObjectsFromArray:root[@"body"]];
- if (weakSelf.dataurce.count != 0) {
- _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{
-
- // NSDictionary * dic = self.dataurce[indexPath.row];
- //
- // __weak typeof(self) weakSelf = self;
- // ComListCell * cell = [ComListCell cellForTabelView:tableView];
- // cell.block = ^{
- // __strong typeof(weakSelf) strongSelf = weakSelf;
- // ComDealVC * vc = [[ComDealVC alloc]init];
- // vc.theId = dic[@"ID"];
- // vc.block = ^{
- // [_heightArr removeAllObjects];
- // [strongSelf headerRefresh];
- // };
- // [strongSelf.navigationController pushViewController:vc animated:YES];
- // };
- // [cell updateWithDic:dic];
- // return cell;
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- // //缓存高度
- // NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
- //
- // if (cellHeight) {
- //
- // return [cellHeight floatValue];
- //
- // }else{
- //
- // NSDictionary * dic = self.dataurce[indexPath.row];
- // CGFloat h1 = [self getHeightWithString:dic[@"CONTENT"]];
- // CGFloat h2 = [self getHeightWithString:dic[@"SCHOPINION"]];
- // CGFloat h3 = [self getHeightWithString:dic[@"DEPTOPINION"]];
- // CGFloat h4 = [self getHeightWithString:dic[@"COACHNAME"]];
- //
- // CGFloat H = 82+h1+h2+h3+h4;//82为其它固定高度
- // [_heightArr addObject:@(H)];
- // return H;
- // }
- return 0;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- EAreasImagesShowVC * vc = [[EAreasImagesShowVC alloc]init];
- [self navPushHideTabbarToVC:vc];
- }
- #pragma mark 计算高度
- -(CGFloat)getHeightWithString:(NSString *)str{
-
- if (str.length == 0) {
- return 0;
- }
-
- NSString * newStr = [NSString stringWithFormat:@"投诉管理 :%@",str];
- CGFloat w = self.tableView.frame.size.width-40;
- CGFloat h1 = [newStr heightForWid:w Font:14];
- return h1+5;//5是间隔
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|