ActivityTableController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //
  2. // ActivityTableController.m
  3. // ZhongJingLianMeng
  4. //
  5. // Created by youke on 2018/11/19.
  6. // Copyright © 2018 youke. All rights reserved.
  7. //
  8. #import "ActivityTableController.h"
  9. #import "newImageCell.h"
  10. #import "activityCell.h"
  11. #import "newModel.h"
  12. #import "newsDetailVController.h"
  13. #import "activityDetailVController.h"
  14. #import "activityModel.h"
  15. @interface ActivityTableController ()<UITableViewDelegate,UITableViewDataSource>{
  16. int _page;
  17. }
  18. @property(nonatomic, strong) UILabel *titleLab;
  19. @property(nonatomic,strong)UITableView *tableView;
  20. @property(nonatomic,strong)NSMutableArray *listArray;
  21. @property(nonatomic,strong)NSMutableArray *dataArray;
  22. @property(nonatomic,strong)HttpRequestManger *sessionManager;
  23. @property(nonatomic,strong)UIImageView *iconImgView;
  24. @property(nonatomic,strong)UILabel *jieKuanLb;
  25. @property(nonatomic,strong)UIView *backgroundView;
  26. @end
  27. @implementation ActivityTableController
  28. - (HttpRequestManger*) sessionManager{
  29. if (!_sessionManager) {
  30. _sessionManager = [[HttpRequestManger alloc]init];
  31. }
  32. return _sessionManager;
  33. }
  34. -(NSMutableArray *)listArray{
  35. if (!_listArray) {
  36. _listArray = [NSMutableArray array];
  37. }
  38. return _listArray;
  39. }
  40. -(NSMutableArray *)dataArray{
  41. if (!_dataArray) {
  42. _dataArray = [NSMutableArray array];
  43. }
  44. return _dataArray;
  45. }
  46. -(void)viewWillAppear:(BOOL)animated{
  47. [super viewWillAppear:YES];
  48. }
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. // [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]];
  52. self.view.backgroundColor = [UIColor whiteColor];
  53. _page = 1;
  54. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,15, kGScreenWidth, kGScreenHeight-NaviHeight -54-15 ) style:UITableViewStylePlain];
  55. _tableView.backgroundColor = [UIColor colorWithHexValue:0xFFFFFF];
  56. self.view.backgroundColor = [UIColor colorWithHexValue:0xFFFFFF];//cell不对齐
  57. [self.view addSubview:_tableView];
  58. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  59. if (@available(iOS 11.0, *)) {
  60. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  61. }else {
  62. self.automaticallyAdjustsScrollViewInsets = NO;
  63. }
  64. _dataArray = [NSMutableArray array];
  65. [self loadStutasList:self.typeString];
  66. _tableView.delegate = self;
  67. _tableView.dataSource = self;
  68. _tableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
  69. [self.dataArray removeAllObjects];
  70. _page = 1;
  71. [self loadStutasList:_typeString];
  72. }];
  73. // 设置自动切换透明度(在导航栏下面自动隐藏)
  74. _tableView.mj_header.automaticallyChangeAlpha = YES;
  75. // 上拉加载
  76. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  77. _page++;
  78. [self loadStutasList:_typeString];
  79. }];
  80. // Do any additional setup after loading the view.
  81. }
  82. -(void)loadStutasList:(NSString *)typeStr{
  83. if (_backgroundView) {
  84. [_backgroundView removeFromSuperview];
  85. }
  86. NSMutableDictionary *parme = [NSMutableDictionary dictionary];
  87. parme[@"type"] = typeStr;
  88. parme[@"pageNum"] = [NSString stringWithFormat:@"%d",_page];
  89. parme[@"pageSize"] = @10;
  90. [ProgressHUD show];
  91. kWeakSelf(self);
  92. [self.sessionManager sendPostHttpRequestWithUrl:activityList params:parme bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  93. [ProgressHUD hide];
  94. NSLog(@"%@",response);
  95. NSArray *arr = [NSArray arrayWithArray:response[@"activityList"]];
  96. if (arr.count !=0 ) {
  97. _listArray = [activityModel mj_objectArrayWithKeyValuesArray:arr];
  98. [_dataArray addObjectsFromArray:_listArray];
  99. }else if([arr count] ==0 && _page !=1){
  100. _listArray = [NSMutableArray arrayWithArray:arr];
  101. }else{
  102. _backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0,NaviHeight +44, kGScreenWidth, kGScreenHeight)];
  103. [self.view addSubview:_backgroundView];
  104. _iconImgView = [[UIImageView alloc] init];
  105. _iconImgView.image = [UIImage imageNamed:@"searchEmptyImg"];
  106. _iconImgView.contentMode = UIViewContentModeScaleAspectFit;
  107. [_backgroundView addSubview:_iconImgView];
  108. [_iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.size.mas_equalTo(CGSizeMake(167, 90));
  110. make.centerY.mas_equalTo(self.view.mas_centerY).with.offset(IS_IPHONE_4_OR_LESS?-60:-140);
  111. make.centerX.mas_equalTo(self.view.mas_centerX).with.offset(0);
  112. }];
  113. _jieKuanLb = [[UILabel alloc] init];
  114. _jieKuanLb.text = @"抱歉,暂无内容~";
  115. _jieKuanLb.font = [UIFont systemFontOfSize:18];
  116. _jieKuanLb.textAlignment = NSTextAlignmentCenter;
  117. [_backgroundView addSubview:_jieKuanLb];
  118. [_jieKuanLb mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.size.mas_equalTo(CGSizeMake(kGScreenWidth, 24));
  120. make.top.mas_equalTo(_iconImgView.mas_bottom).with.offset(10);
  121. make.centerX.mas_equalTo(self.view.mas_centerX).with.offset(0);
  122. }];
  123. }
  124. [weakself reloadTableView];
  125. } failure:^(NSError *error) {
  126. [ProgressHUD hide];
  127. NSLog(@"%@",error);
  128. }];
  129. }
  130. -(void)reloadTableView{
  131. [_tableView reloadData];
  132. [_tableView.mj_header endRefreshing];
  133. [_tableView.mj_footer endRefreshing];
  134. if (self.dataArray.count%10!=0||self.listArray.count%10!=0) {
  135. [_tableView.mj_footer endRefreshingWithNoMoreData];
  136. }
  137. }
  138. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  139. {
  140. if ([_typeString isEqualToString:@"1"]) {
  141. return _dataArray.count;
  142. }else{
  143. return 1;
  144. }
  145. }
  146. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  147. {
  148. if ([_typeString isEqualToString:@"1"]) {
  149. return 1;
  150. }else{
  151. return _dataArray.count;
  152. }
  153. }
  154. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  155. {
  156. if ([_typeString isEqualToString:@"1"]) {
  157. return 260;
  158. }else{
  159. return 115;
  160. }
  161. }
  162. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. if ([_typeString isEqualToString:@"1"]) {
  165. activityModel *model = _dataArray[indexPath.section];
  166. activityCell *cell = [activityCell cellWith:model tableView:tableView];
  167. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  168. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  169. return cell;
  170. }else{
  171. activityModel *model = _dataArray[indexPath.row];
  172. newImageCell *cell = [newImageCell cell1With:model tableView:tableView];
  173. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  174. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  175. return cell;
  176. }
  177. }
  178. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  179. if (section == 0) {
  180. return 0.0001;
  181. }else{
  182. return 15;
  183. }
  184. }
  185. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  186. return 0.0001;
  187. }
  188. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  189. if (section == 0) {
  190. return nil;
  191. }else{
  192. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kGScreenWidth, 15)];
  193. view.backgroundColor = [UIColor whiteColor];
  194. return view;
  195. }
  196. }
  197. -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  198. return nil;
  199. }
  200. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  201. if ([_typeString isEqualToString:@"1"]) {
  202. activityModel *model = self.dataArray[indexPath.section];
  203. activityDetailVController *activityDetail = [[activityDetailVController alloc]init];
  204. activityDetail.newsId = model.news_Id;
  205. activityDetail.titleStr = model.title;
  206. activityDetail.shareTitle = model.title;
  207. activityDetail.activityStatus = model.status;
  208. activityDetail.index =@"0";
  209. activityDetail.urlStr = [NSString stringWithFormat:@"%@/applyDetail?id=%@&move=ios",baseH5,model.news_Id];
  210. activityDetail.shareUrl = [NSString stringWithFormat:@"%@/applyDetail?id=%@",baseH5,model.news_Id];
  211. [self.navigationController pushViewController:activityDetail animated:YES];
  212. }else{
  213. activityModel *model = self.dataArray[indexPath.row];
  214. newsDetailVController *newsDetail = [[newsDetailVController alloc]init];
  215. newsDetail.newsId = model.news_Id;
  216. newsDetail.titleStr = model.title;
  217. newsDetail.shareTitle = model.title;
  218. newsDetail.typeStr = @"2";
  219. newsDetail.index =@"0";
  220. newsDetail.urlStr = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,model.news_Id];
  221. newsDetail.shareUrl = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,model.news_Id];
  222. [self.navigationController pushViewController:newsDetail animated:YES];
  223. }
  224. }
  225. - (void)dealloc {
  226. if (_sessionManager) {
  227. [_sessionManager cancelAllTask];
  228. }
  229. DebugLog(@"%@没有造成循环引用", [self class]);
  230. }
  231. - (void)didReceiveMemoryWarning {
  232. [super didReceiveMemoryWarning];
  233. // Dispose of any resources that can be recreated.
  234. }
  235. /*
  236. #pragma mark - Navigation
  237. // In a storyboard-based application, you will often want to do a little preparation before navigation
  238. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  239. // Get the new view controller using [segue destinationViewController].
  240. // Pass the selected object to the new view controller.
  241. }
  242. */
  243. @end