GuideHtmlVC.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // GuideHtmlVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/4/29.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "GuideHtmlVC.h"
  9. #import "HolderView.h"
  10. #import "newDetailVC.h"
  11. #import "NewListNoImg.h"
  12. #import "NewsDetVC.h"
  13. #import "Tools.h"
  14. @interface GuideHtmlVC ()<UITableViewDelegate,UITableViewDataSource>
  15. {
  16. NSInteger currentPage;
  17. NSMutableArray *newsList;
  18. UITableView *mainTableView;
  19. HolderView *placeHolder;
  20. }
  21. @end
  22. @implementation GuideHtmlVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.navigationController.navigationBar.backgroundColor = backGroundColor;
  26. self.view.backgroundColor = [UIColor whiteColor];
  27. [self configNavigationBar];
  28. newsList = [NSMutableArray array];
  29. currentPage = 1;
  30. CGFloat x,y,w,h;
  31. x = 0;
  32. y = 0;
  33. w = kSize.width;
  34. h = kSize.height - kNavOffSet;
  35. mainTableView = [[UITableView alloc] setxywh style:UITableViewStylePlain];
  36. mainTableView.delegate = self;
  37. mainTableView.dataSource = self;
  38. mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  39. [self.view addSubview:mainTableView];
  40. placeHolder = [[HolderView alloc] initWithFrame:mainTableView.frame];
  41. [placeHolder freshBlock:^{
  42. currentPage = 1;
  43. [self getNewsInfoByItemId];
  44. }];
  45. [self.view addSubview:placeHolder];
  46. //默认显示新闻
  47. [self getNewsInfoByItemId];
  48. }
  49. #pragma mark 异步获取新闻列表
  50. -(void)getNewsInfoByItemId
  51. {
  52. if (![Util connectedToNetWork]) {
  53. showMsgUnconnect();
  54. return;
  55. }
  56. NSMutableArray *arr=[NSMutableArray array];
  57. [arr addPro:@"itemId" Value:_searchID];
  58. [arr addPro:@"isPage" Value:@"1"];
  59. [arr addPro:@"pageSize" Value:@"10"];
  60. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
  61. NSString* method = @"getNewsInfoByItemId";
  62. [MBProgressHUD showLoadToView:self.view];
  63. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  64. [MBProgressHUD hideHUDForView:self.view];
  65. //NSLog(@"getNewsInfoByItemId---%@--->%@",arr,root);
  66. if (newsList.count > 0) {
  67. placeHolder.hidden = YES;
  68. }else {
  69. placeHolder.hidden = NO;
  70. }
  71. if (!root)
  72. {
  73. [LoadingView showMsg:@"网络请求失败!"];
  74. return;
  75. }
  76. if ([root[@"code"] isEqualToString:@"1"]) {
  77. ShowMsg(root[@"body"]);
  78. return;
  79. }
  80. if ([root[@"body"] count] < 1) {
  81. ShowMsg(@"已加载全部");
  82. return;
  83. }
  84. if (currentPage == 1) {
  85. newsList = [NSMutableArray arrayWithArray:root[@"body"]];
  86. }else{
  87. [newsList addObjectsFromArray:root[@"body"]];
  88. }
  89. currentPage ++;
  90. placeHolder.hidden = YES;
  91. [mainTableView reloadData];
  92. }];
  93. }
  94. #pragma mark maintableView delegate
  95. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  96. {
  97. return newsList.count;
  98. }
  99. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  100. {
  101. NSDictionary* dic = newsList[indexPath.row];
  102. if ([dic[@"ISIMG"] isEqualToString:@"0"]) {
  103. NewListNoImg *cell = [tableView dequeueReusableCellWithIdentifier:@"newNoImg"];
  104. if (cell == nil)
  105. {
  106. NSArray * viewArray = [[NSBundle mainBundle] loadNibNamed:@"NewListNoImg" owner:nil options:nil];
  107. cell = [viewArray firstObject];
  108. }
  109. cell.titleLabel.text = dic[@"TITLE"];
  110. // if ([dic[@"LIGHT"] isEqualToString:@"0"]) {
  111. // cell.titleLabel.textColor = kTitleColor;
  112. // }else{
  113. // cell.titleLabel.textColor = [UIColor redColor];
  114. // }
  115. cell.dateLabel.text = dic[@"ADDTIME"];
  116. if ([dic[@"ADDTIME"] length] > 10) {
  117. cell.dateLabel.text = [dic[@"ADDTIME"] substringToIndex:10];
  118. }
  119. if ([dic[@"ADDTIME"] isEqualToString:@""]) {
  120. cell.dateLabel.text = @"摘自网络";
  121. }
  122. cell.countLabel.text = [NSString stringWithFormat:@"阅读:%@",[Tools isWan:dic[@"READNUM"]]];
  123. if ([dic[@"REMARK"] length] > 0) {
  124. cell.contentLabel.text = [NSString stringWithFormat:@" %@",[dic[@"REMARK"] stringByReplacingOccurrencesOfString:@"&amp;" withString:@""]];
  125. }
  126. return cell;
  127. }else{
  128. newDetailVC *cell = [tableView dequeueReusableCellWithIdentifier:@"newCell"];
  129. if (cell == nil)
  130. {
  131. NSArray * viewArray = [[NSBundle mainBundle] loadNibNamed:@"newDetailVC" owner:nil options:nil];
  132. cell = [viewArray firstObject];
  133. }
  134. //设置图片大小不变 超出部分截掉
  135. cell.headImg.contentMode = UIViewContentModeScaleAspectFill;
  136. cell.headImg.clipsToBounds = YES;
  137. //dansonimg
  138. [cell.headImg sd_setImageWithURL:[NSURL URLWithString:dic[@"IMGPATH"]] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]];
  139. //设置标题及标题颜色
  140. cell.titleLabel.text = dic[@"TITLE"];
  141. // if ([dic[@"LIGHT"] isEqualToString:@"0"]) {
  142. // cell.titleLabel.textColor = kTitleColor;
  143. // }else{
  144. // cell.titleLabel.textColor = [UIColor redColor];
  145. // }
  146. cell.sourceLabel.text = dic[@"ADDTIME"];
  147. if ([dic[@"ADDTIME"] length] > 10) {
  148. cell.sourceLabel.text = [dic[@"ADDTIME"] substringToIndex:10];
  149. }
  150. if ([dic[@"ADDTIME"] isEqualToString:@""]) {
  151. cell.sourceLabel.text = @"摘自网络";
  152. }
  153. cell.readCount.text = [NSString stringWithFormat:@"阅读:%@",[Tools isWan:dic[@"READNUM"]]];
  154. if ([dic[@"REMARK"] length] > 0) {
  155. cell.contentLabel.text = [NSString stringWithFormat:@" %@",[dic[@"REMARK"] stringByReplacingOccurrencesOfString:@"&amp;" withString:@""]];
  156. }
  157. return cell;
  158. }
  159. }
  160. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  161. {
  162. NSDictionary *dic = newsList[indexPath.row];
  163. if ([dic[@"ISIMG"] isEqualToString:@"0"]) {
  164. return 110;
  165. }else{
  166. return 130;
  167. }
  168. }
  169. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  170. {
  171. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  172. NSDictionary *dic = newsList[indexPath.row];
  173. NewsDetVC* vc = [[NewsDetVC alloc] init];
  174. vc.preModel = dic;
  175. vc.type = @"3";
  176. [self navPushHideTabbarToVC:vc];
  177. }
  178. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  179. {
  180. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  181. return view;
  182. }
  183. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  184. {
  185. return .1;
  186. }
  187. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  188. {
  189. //NSLog(@"%d",(int)scrollView.tag);
  190. if (scrollView.tag == 2) {
  191. return;
  192. }
  193. CGPoint off = scrollView.contentOffset;
  194. if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  195. [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  196. [self getNewsInfoByItemId];
  197. }
  198. }
  199. - (void)didReceiveMemoryWarning {
  200. [super didReceiveMemoryWarning];
  201. // Dispose of any resources that can be recreated.
  202. }
  203. @end