ReportListVC.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // ReportListVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/5/31.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. //废弃
  9. #import "ReportListVC.h"
  10. #import "RepListCell.h"
  11. #import "MJRefresh.h"
  12. #import "NSArray+ex.h"
  13. #import "NSString+ex.h"
  14. @interface ReportListVC ()
  15. {
  16. //记录页书
  17. NSInteger _currentPageNum;
  18. //加载数据的类型
  19. MyGetDataType _getDataType;
  20. //缓存高度
  21. NSMutableArray * _heightArr;
  22. }
  23. @end
  24. @implementation ReportListVC
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  28. _currentPageNum = 0;
  29. _getDataType = MyGetDataTypeNomal;
  30. [self setRefreshAction];//设置刷新
  31. [self getData];
  32. __weak typeof(self) weakSelf = self;
  33. self.block = ^{
  34. _currentPageNum = 0;
  35. [weakSelf getData];
  36. };
  37. }
  38. #pragma mark - 下拉刷新,上拉加载 -
  39. -(void)setRefreshAction{
  40. // 下拉加载更多
  41. __weak typeof(self) weakSelf = self;
  42. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  43. [weakSelf headerRefresh];
  44. }];
  45. self.tableView.mj_header = header;
  46. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  47. [weakSelf footerRefresh];
  48. }];
  49. self.tableView.mj_footer = footer;
  50. }
  51. -(void)headerRefresh{
  52. //设置获取数据的方式
  53. _getDataType=MyGetDataTypeHeaderRefresh;
  54. //加载数据
  55. [self getData];
  56. [self.tableView.mj_header endRefreshing];
  57. }
  58. -(void)footerRefresh{
  59. //设置获取数据的方式
  60. _getDataType=MyGetDataTypeFooterRefresh;
  61. //加载数据
  62. [self getData];
  63. [self.tableView.mj_footer endRefreshing];
  64. }
  65. -(void)getData{
  66. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  67. if (_IS_LOADING) {
  68. return;
  69. }
  70. _IS_LOADING=YES;
  71. //获取第一页数据
  72. NSInteger needLoadPage;
  73. needLoadPage=_currentPageNum+1;
  74. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  75. needLoadPage=1;
  76. }
  77. NSMutableDictionary * mDic = [NSMutableDictionary new];
  78. [mDic setObject:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
  79. [mDic setObject:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
  80. [mDic setObject:@"1" forKey:@"isPage"];
  81. [mDic setObject:@"10" forKey:@"pageSize"];
  82. [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
  83. __weak typeof(self) weakSelf = self;
  84. [self getDataWithDic:mDic method:@"getReports" block:^(NSDictionary *successDic) {
  85. //处理数据
  86. //如果获取到了数据,而且是下拉刷新,清空数组。
  87. if (_getDataType==MyGetDataTypeHeaderRefresh){
  88. [weakSelf.dataurce removeAllObjects];
  89. }
  90. //追加数据
  91. [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]];
  92. if (weakSelf.dataurce.count != 0) {
  93. weakSelf.holderV.hidden = YES;
  94. }
  95. //计数器+1
  96. _currentPageNum=needLoadPage;
  97. //刷新界面
  98. [weakSelf.tableView reloadData];
  99. //恢复初始状态。
  100. _getDataType=MyGetDataTypeNomal;
  101. }];
  102. }
  103. #pragma mark tableView代理方法
  104. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  105. return self.dataurce.count;
  106. }
  107. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  108. RepListCell * cell = [RepListCell cellForTabelView:tableView];
  109. [cell updateWithDic:self.dataurce[indexPath.row]];
  110. return cell;
  111. }
  112. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  113. //缓存高度
  114. NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
  115. if (cellHeight) {
  116. return [cellHeight floatValue];
  117. }else{
  118. CGFloat h1 = 0;
  119. NSDictionary * dic = self.dataurce[indexPath.row];
  120. if ([dic[@"content"] length] != 0) {
  121. CGFloat w = self.tableView.frame.size.width-40;
  122. NSString *str = [NSString stringWithFormat:@"举报内容 :%@",dic[@"content"]];
  123. h1 = [str heightForWid:w Font:14] + 5;
  124. }
  125. CGFloat H = 97+h1;//67为其它固定高度
  126. [_heightArr addObject:@(H)];
  127. return H;
  128. }
  129. }
  130. - (void)didReceiveMemoryWarning {
  131. [super didReceiveMemoryWarning];
  132. // Dispose of any resources that can be recreated.
  133. }
  134. @end