allianceNewsVController.m 8.7 KB

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