EAreasListVC.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //
  2. // EAreasListVC
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/6/16.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "EAreasListVC.h"
  9. #import "MJRefresh.h"
  10. #import "EAreasImagesShowVC.h"
  11. typedef NS_ENUM(NSInteger, MyGetDataType) {
  12. //正常请求数据
  13. MyGetDataTypeNomal=0,
  14. //下拉刷新请求数据
  15. MyGetDataTypeHeaderRefresh,
  16. //上拉加载更多请求数据
  17. MyGetDataTypeFooterRefresh
  18. };
  19. @interface EAreasListVC ()<UITableViewDataSource,UITableViewDelegate>
  20. {
  21. //记录页书
  22. NSInteger _currentPageNum;
  23. //正在加载的状态
  24. BOOL _IS_LOADING;
  25. //加载数据的类型
  26. MyGetDataType _getDataType;
  27. //
  28. HolderView *_holderV;
  29. //缓存cell高度
  30. NSMutableArray * _heightArr;
  31. }
  32. @property (nonatomic,retain)NSMutableArray * dataurce;
  33. @property(nonatomic,retain)UITableView *tableView;
  34. @end
  35. @implementation EAreasListVC
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. self.navigationItem.title = @"电子围栏";
  39. self.view.backgroundColor = KBackGroundColor;
  40. self.navigationController.navigationBar.translucent = NO;
  41. _dataurce = [[NSMutableArray alloc]init];
  42. _currentPageNum = 0;
  43. _IS_LOADING = NO;
  44. _getDataType = MyGetDataTypeNomal;
  45. _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
  46. _tableView.backgroundColor = KBackGroundColor;
  47. _tableView.dataSource = self;
  48. _tableView.delegate = self;
  49. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  50. _tableView.sectionHeaderHeight = 20;
  51. _tableView.tableFooterView = [UIView new];
  52. [self.view addSubview:_tableView];
  53. [self goBackByNavigation];
  54. [self getData];
  55. _holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
  56. _holderV.y = kNavOffSet;
  57. [_holderV freshBlock:^{
  58. [self headerRefresh];
  59. }];
  60. [self.view addSubview:_holderV];
  61. }
  62. #pragma mark - 下拉刷新,上拉加载 -
  63. -(void)setRefreshAction{
  64. // 下拉刷新
  65. __weak typeof(self) weakSelf = self;
  66. MJRefreshGifHeader * header = [self.tableView addGifHeaderWithRefreshingBlock:^{
  67. [weakSelf headerRefresh];
  68. }];
  69. header.updatedTimeHidden = YES;
  70. MJRefreshFooter *foot = [self.tableView addGifFooterWithRefreshingBlock:^{
  71. [weakSelf footerRefresh];
  72. }];
  73. foot.automaticallyRefresh = YES;
  74. }
  75. #pragma mark - 数据加载更多和刷新 -
  76. -(void)headerRefresh{
  77. //设置获取数据的方式
  78. _getDataType=MyGetDataTypeHeaderRefresh;
  79. //加载数据
  80. [self getData];
  81. }
  82. -(void)footerRefresh{
  83. //设置获取数据的方式
  84. _getDataType=MyGetDataTypeFooterRefresh;
  85. //加载数据
  86. [self getData];
  87. }
  88. -(void)getData{
  89. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  90. if (_IS_LOADING) {
  91. return;
  92. }
  93. if (![NetManager connectedToNetWork]) {
  94. showMsgUnconnect();
  95. return;
  96. }
  97. _IS_LOADING=YES;
  98. //获取第一页数据
  99. NSInteger needLoadPage;
  100. needLoadPage=_currentPageNum+1;
  101. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  102. needLoadPage=1;
  103. }
  104. NSMutableDictionary * mDic = [NSMutableDictionary new];
  105. [mDic setObject:defUser.userDict[@"school"] forKey:@"jxbh"];
  106. // [mDic setObject:@"1" forKey:@"isPage"];
  107. // [mDic setObject:@"10" forKey:@"pageSize"];
  108. // [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
  109. __weak typeof(self) weakSelf = self;
  110. [NetManager requestAnythingWithURL:@"getAreas" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  111. _holderV.hidden = YES;
  112. //设置加载状态
  113. _IS_LOADING=NO;
  114. if (!root) {
  115. ShowErrorMsg(@"请求失败!");
  116. return;
  117. }
  118. if ([root[@"code"] isEqualToString:@"1"]) {
  119. ShowErrorMsg(root[@"msg"]);
  120. return;
  121. }
  122. //如果是上拉加载更多,应该结束上拉刷新的界面。
  123. if (_getDataType==MyGetDataTypeFooterRefresh) {
  124. [weakSelf.tableView.gifFooter endRefreshing];
  125. }
  126. //如果是下拉刷新,应该结束界面刷新状态;
  127. else if (_getDataType==MyGetDataTypeHeaderRefresh){
  128. [weakSelf.tableView.gifHeader endRefreshing];
  129. }
  130. //处理数据
  131. //如果获取到了数据,而且是下拉刷新,清空数组。
  132. if (_getDataType==MyGetDataTypeHeaderRefresh){
  133. [weakSelf.dataurce removeAllObjects];
  134. }
  135. //追加数据
  136. [weakSelf.dataurce addObjectsFromArray:root[@"body"]];
  137. if (weakSelf.dataurce.count != 0) {
  138. _holderV.hidden = YES;
  139. }
  140. //计数器+1
  141. _currentPageNum=needLoadPage;
  142. //刷新界面
  143. // [weakSelf.tableView reloadData];
  144. //恢复初始状态。
  145. _getDataType=MyGetDataTypeNomal;
  146. }];
  147. }
  148. #pragma mark tableView代理方法
  149. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  150. return self.dataurce.count;
  151. }
  152. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  153. // NSDictionary * dic = self.dataurce[indexPath.row];
  154. //
  155. // __weak typeof(self) weakSelf = self;
  156. // ComListCell * cell = [ComListCell cellForTabelView:tableView];
  157. // cell.block = ^{
  158. // __strong typeof(weakSelf) strongSelf = weakSelf;
  159. // ComDealVC * vc = [[ComDealVC alloc]init];
  160. // vc.theId = dic[@"ID"];
  161. // vc.block = ^{
  162. // [_heightArr removeAllObjects];
  163. // [strongSelf headerRefresh];
  164. // };
  165. // [strongSelf.navigationController pushViewController:vc animated:YES];
  166. // };
  167. // [cell updateWithDic:dic];
  168. // return cell;
  169. return nil;
  170. }
  171. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  172. // //缓存高度
  173. // NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
  174. //
  175. // if (cellHeight) {
  176. //
  177. // return [cellHeight floatValue];
  178. //
  179. // }else{
  180. //
  181. // NSDictionary * dic = self.dataurce[indexPath.row];
  182. // CGFloat h1 = [self getHeightWithString:dic[@"CONTENT"]];
  183. // CGFloat h2 = [self getHeightWithString:dic[@"SCHOPINION"]];
  184. // CGFloat h3 = [self getHeightWithString:dic[@"DEPTOPINION"]];
  185. // CGFloat h4 = [self getHeightWithString:dic[@"COACHNAME"]];
  186. //
  187. // CGFloat H = 82+h1+h2+h3+h4;//82为其它固定高度
  188. // [_heightArr addObject:@(H)];
  189. // return H;
  190. // }
  191. return 0;
  192. }
  193. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  194. EAreasImagesShowVC * vc = [[EAreasImagesShowVC alloc]init];
  195. [self navPushHideTabbarToVC:vc];
  196. }
  197. #pragma mark 计算高度
  198. -(CGFloat)getHeightWithString:(NSString *)str{
  199. if (str.length == 0) {
  200. return 0;
  201. }
  202. NSString * newStr = [NSString stringWithFormat:@"投诉管理 :%@",str];
  203. CGFloat w = self.tableView.frame.size.width-40;
  204. CGFloat h1 = [newStr heightForWid:w Font:14];
  205. return h1+5;//5是间隔
  206. }
  207. - (void)didReceiveMemoryWarning {
  208. [super didReceiveMemoryWarning];
  209. // Dispose of any resources that can be recreated.
  210. }
  211. /*
  212. #pragma mark - Navigation
  213. // In a storyboard-based application, you will often want to do a little preparation before navigation
  214. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  215. // Get the new view controller using [segue destinationViewController].
  216. // Pass the selected object to the new view controller.
  217. }
  218. */
  219. @end