// // ActivityTableController.m // ZhongJingLianMeng // // Created by youke on 2018/11/19. // Copyright © 2018 youke. All rights reserved. // #import "ActivityTableController.h" #import "newImageCell.h" #import "activityCell.h" #import "newModel.h" #import "newsDetailVController.h" #import "activityDetailVController.h" #import "activityModel.h" @interface ActivityTableController (){ int _page; } @property(nonatomic, strong) UILabel *titleLab; @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong)NSMutableArray *listArray; @property(nonatomic,strong)NSMutableArray *dataArray; @property(nonatomic,strong)HttpRequestManger *sessionManager; @property(nonatomic,strong)UIImageView *iconImgView; @property(nonatomic,strong)UILabel *jieKuanLb; @property(nonatomic,strong)UIView *backgroundView; @end @implementation ActivityTableController - (HttpRequestManger*) sessionManager{ if (!_sessionManager) { _sessionManager = [[HttpRequestManger alloc]init]; } return _sessionManager; } -(NSMutableArray *)listArray{ if (!_listArray) { _listArray = [NSMutableArray array]; } return _listArray; } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; } - (void)viewDidLoad { [super viewDidLoad]; // [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]]; self.view.backgroundColor = [UIColor whiteColor]; _page = 1; _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,15, kGScreenWidth, kGScreenHeight-NaviHeight -54-15 ) style:UITableViewStylePlain]; _tableView.backgroundColor = [UIColor colorWithHexValue:0xFFFFFF]; self.view.backgroundColor = [UIColor colorWithHexValue:0xFFFFFF];//cell不对齐 [self.view addSubview:_tableView]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; if (@available(iOS 11.0, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; }else { self.automaticallyAdjustsScrollViewInsets = NO; } _dataArray = [NSMutableArray array]; [self loadStutasList:self.typeString]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{ [self.dataArray removeAllObjects]; _page = 1; [self loadStutasList:_typeString]; }]; // 设置自动切换透明度(在导航栏下面自动隐藏) _tableView.mj_header.automaticallyChangeAlpha = YES; // 上拉加载 _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ _page++; [self loadStutasList:_typeString]; }]; // Do any additional setup after loading the view. } -(void)loadStutasList:(NSString *)typeStr{ if (_backgroundView) { [_backgroundView removeFromSuperview]; } NSMutableDictionary *parme = [NSMutableDictionary dictionary]; parme[@"type"] = typeStr; parme[@"pageNum"] = [NSString stringWithFormat:@"%d",_page]; parme[@"pageSize"] = @10; [ProgressHUD show]; kWeakSelf(self); [self.sessionManager sendPostHttpRequestWithUrl:activityList params:parme bodyBlock:nil progress:nil success:^(NSDictionary *response) { [ProgressHUD hide]; NSLog(@"%@",response); NSArray *arr = [NSArray arrayWithArray:response[@"activityList"]]; if (arr.count !=0 ) { _listArray = [activityModel mj_objectArrayWithKeyValuesArray:arr]; [_dataArray addObjectsFromArray:_listArray]; }else if([arr count] ==0 && _page !=1){ _listArray = [NSMutableArray arrayWithArray:arr]; }else{ _backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0,NaviHeight +44, kGScreenWidth, kGScreenHeight)]; [self.view addSubview:_backgroundView]; _iconImgView = [[UIImageView alloc] init]; _iconImgView.image = [UIImage imageNamed:@"searchEmptyImg"]; _iconImgView.contentMode = UIViewContentModeScaleAspectFit; [_backgroundView addSubview:_iconImgView]; [_iconImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(167, 90)); make.centerY.mas_equalTo(self.view.mas_centerY).with.offset(IS_IPHONE_4_OR_LESS?-60:-140); make.centerX.mas_equalTo(self.view.mas_centerX).with.offset(0); }]; _jieKuanLb = [[UILabel alloc] init]; _jieKuanLb.text = @"抱歉,暂无内容~"; _jieKuanLb.font = [UIFont systemFontOfSize:18]; _jieKuanLb.textAlignment = NSTextAlignmentCenter; [_backgroundView addSubview:_jieKuanLb]; [_jieKuanLb mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(kGScreenWidth, 24)); make.top.mas_equalTo(_iconImgView.mas_bottom).with.offset(10); make.centerX.mas_equalTo(self.view.mas_centerX).with.offset(0); }]; } [weakself reloadTableView]; } failure:^(NSError *error) { [ProgressHUD hide]; NSLog(@"%@",error); }]; } -(void)reloadTableView{ [_tableView reloadData]; [_tableView.mj_header endRefreshing]; [_tableView.mj_footer endRefreshing]; if (self.dataArray.count%10!=0||self.listArray.count%10!=0) { [_tableView.mj_footer endRefreshingWithNoMoreData]; } } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if ([_typeString isEqualToString:@"1"]) { return _dataArray.count; }else{ return 1; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if ([_typeString isEqualToString:@"1"]) { return 1; }else{ return _dataArray.count; } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if ([_typeString isEqualToString:@"1"]) { return 260; }else{ return 115; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([_typeString isEqualToString:@"1"]) { activityModel *model = _dataArray[indexPath.section]; activityCell *cell = [activityCell cellWith:model tableView:tableView]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else{ activityModel *model = _dataArray[indexPath.row]; newImageCell *cell = [newImageCell cell1With:model tableView:tableView]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 0) { return 0.0001; }else{ return 15; } } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.0001; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section == 0) { return nil; }else{ UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kGScreenWidth, 15)]; view.backgroundColor = [UIColor whiteColor]; return view; } } -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ return nil; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_typeString isEqualToString:@"1"]) { activityModel *model = self.dataArray[indexPath.section]; activityDetailVController *activityDetail = [[activityDetailVController alloc]init]; activityDetail.newsId = model.news_Id; activityDetail.titleStr = model.title; activityDetail.shareTitle = model.title; activityDetail.activityStatus = model.status; activityDetail.index =@"0"; activityDetail.urlStr = [NSString stringWithFormat:@"%@/applyDetail?id=%@&move=ios",baseH5,model.news_Id]; activityDetail.shareUrl = [NSString stringWithFormat:@"%@/applyDetail?id=%@",baseH5,model.news_Id]; [self.navigationController pushViewController:activityDetail animated:YES]; }else{ activityModel *model = self.dataArray[indexPath.row]; newsDetailVController *newsDetail = [[newsDetailVController alloc]init]; newsDetail.newsId = model.news_Id; newsDetail.titleStr = model.title; newsDetail.shareTitle = model.title; newsDetail.typeStr = @"2"; newsDetail.index =@"0"; newsDetail.urlStr = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,model.news_Id]; newsDetail.shareUrl = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,model.news_Id]; [self.navigationController pushViewController:newsDetail animated:YES]; } } - (void)dealloc { if (_sessionManager) { [_sessionManager cancelAllTask]; } DebugLog(@"%@没有造成循环引用", [self class]); } - (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