123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- //
- // allianceNewsVController.m
- // ZhongJingLianMeng
- //
- // Created by youke on 2018/11/16.
- // Copyright © 2018 youke. All rights reserved.
- //
- #import "allianceNewsVController.h"
- #import "newModel.h"
- #import "newImageCell.h"
- #import "newNoImageCell.h"
- #import "newModel.h"
- #import "newsDetailVController.h"
- @interface allianceNewsVController ()<UITableViewDelegate,UITableViewDataSource>{
-
- int _page;
- }
- @property(nonatomic,strong)UILabel *titleLab;
- @property(nonatomic,strong)UITableView *tab;
- @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 allianceNewsVController
- - (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)viewDidLoad {
- [super viewDidLoad];
-
- [self.navigationView removeAllLeftButton];
- self.view.backgroundColor = [UIColor colorWithHexValue:0xF7F8FA];
- _titleLab = [[UILabel alloc]init];
-
- _titleLab.frame = CGRectMake(0,0, kGScreenWidth-60, 30);
-
- _titleLab.textColor = [UIColor whiteColor];
-
- _page = 1;
- [self loadDataList:_typeString];
-
- _dataArray = [NSMutableArray array];
-
- if ([_typeString isEqualToString:@"1"]) {
-
- _titleLab.text = @"联盟公告";
- // [self loadDataList:_typeString];
- }else{
- _titleLab.text = @"新闻资讯";
- // [self loadDataList:_typeString];
- }
-
- [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]];
-
- [self.navigationView addTitleView:_titleLab];
-
- kWeakSelf(self);
- [self.navigationView addLeftButtonWithImage:[UIImage imageNamed:@"whiteBack"] clickCallBack:^(UIView *view) {
-
- [weakself.navigationController popViewControllerAnimated:YES];
- }];
-
- _tab = [[UITableView alloc]initWithFrame:CGRectMake(0, NaviHeight, kGScreenWidth, kGScreenHeight-NaviHeight ) style:UITableViewStylePlain];
- _tab.delegate = self;
- _tab.dataSource = self;
- _tab.backgroundColor = KRGB_COLOR(247, 249,251);
- _tab.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:_tab];
- if (@available(iOS 11.0, *)) {
- _tab.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- _tab.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
-
- [self.dataArray removeAllObjects];
- _page = 1;
- [self loadDataList:_typeString];
-
- }];
- // 设置自动切换透明度(在导航栏下面自动隐藏)
- _tab.mj_header.automaticallyChangeAlpha = YES;
-
- // 上拉加载
- _tab.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
-
- _page++;
- [self loadDataList:_typeString];
- }];
- // Do any additional setup after loading the view.
- }
- -(void)loadDataList:(NSString *)string{
-
- if (_backgroundView) {
-
- [_backgroundView removeFromSuperview];
- }
- NSMutableDictionary *parem =[NSMutableDictionary dictionary];
- parem[@"pageSize"] = @10;
- parem[@"pageNum"] = [NSString stringWithFormat:@"%d",_page];
- parem[@"type"] = string;
- kWeakSelf(self);
- [ProgressHUD show];
- [weakself.sessionManager sendPostHttpRequestWithUrl:newsInfoList params:parem bodyBlock:nil progress:nil success:^(NSDictionary *response) {
- [ProgressHUD hide];
-
- NSLog(@"%@",response);
-
- NSArray *arr = [NSArray arrayWithArray:response[@"informationList"]];
-
- if (arr.count !=0 ) {
-
- _listArray = [newModel 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:15];
- _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{
- [_tab reloadData];
- [_tab.mj_header endRefreshing];
- [_tab.mj_footer endRefreshing];
- if (self.dataArray.count%10!=0||self.listArray.count%10!=0) {
- [_tab.mj_footer endRefreshingWithNoMoreData];
- }
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return _dataArray.count;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 0.001;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return 0.0001;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 115;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- newModel *model = self.dataArray[indexPath.row];
-
- if ([model.img_path isEqualToString:@""]) {
-
- newNoImageCell *cell = [newNoImageCell cellWith:model tableView:tableView];
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
- }else{
- newImageCell *cell = [newImageCell cellWith:model tableView:tableView];
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
-
- }
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- newModel *model = self.dataArray[indexPath.row];
- newsDetailVController *newsDetail = [[newsDetailVController alloc]init];
- newsDetail.newsId = model.news_Id;
- newsDetail.titleStr = model.title;
- newsDetail.shareTitle = model.title;
- newsDetail.ImgUrl = model.img_path;
- newsDetail.typeStr = @"0";
- newsDetail.index =@"0";
- newsDetail.urlStr = [NSString stringWithFormat:@"%@/newsInfo?id=%@&move=ios",baseH5,model.news_Id];
- newsDetail.shareUrl = [NSString stringWithFormat:@"%@/newsInfo?id=%@",baseH5,model.news_Id];
- [self.navigationController pushViewController:newsDetail animated:YES];
- }
- - (void)dealloc {
- if (_sessionManager) {
- [_sessionManager cancelAllTask];
- }
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- 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
|