NewsOfLearnVC.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // NewsOfLearnVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/12/8.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "NewsOfLearnVC.h"
  9. #import "HolderView.h"
  10. #import "NewsDetVC.h"
  11. #import "NewsOfLearnCell.h"
  12. @interface NewsOfLearnVC ()<UITableViewDataSource,UITableViewDelegate>
  13. {
  14. UITableView* myTableView;
  15. HolderView* holdV;
  16. NSMutableArray* models;
  17. int currentPage;
  18. }
  19. @end
  20. @implementation NewsOfLearnVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self myInit];
  24. }
  25. - (void)didReceiveMemoryWarning {
  26. [super didReceiveMemoryWarning];
  27. // Dispose of any resources that can be recreated.
  28. }
  29. -(void)viewDidAppear:(BOOL)animated
  30. {
  31. [super viewDidAppear:animated];
  32. [self getTopicNews];
  33. }
  34. #pragma mark -
  35. -(void)myInit
  36. {
  37. [self configNavigationBar];
  38. [self setTitle:@"驾考头条"];
  39. [self.view setBackgroundColor:[UIColor whiteColor]];
  40. currentPage = 1;
  41. models = [NSMutableArray array];
  42. holdV = [[HolderView alloc] initWithFrame:kFrame];
  43. [self.view addSubview:holdV];
  44. [holdV setHidden:YES];
  45. [holdV freshBlock:^{
  46. [self getTopicNews];
  47. }];
  48. UITableView* tv = [[UITableView alloc] initWithFrame:kFrame];
  49. tv.height = kSize.height - kNavOffSet;
  50. tv.rowHeight = 92;
  51. tv.separatorStyle = UITableViewCellSeparatorStyleNone;
  52. [self.view addSubview:tv];
  53. myTableView = tv;
  54. [myTableView setDelegate:self];
  55. [myTableView setDataSource:self];
  56. }
  57. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  58. {
  59. NewsOfLearnCell *cell = [tableView dequeueReusableCellWithIdentifier:@"newsCell"];
  60. if (cell == nil)
  61. {
  62. NSArray * viewArray = [[NSBundle mainBundle] loadNibNamed:@"NewsOfLearnCell" owner:nil options:nil];
  63. cell = [viewArray firstObject];
  64. }
  65. NSDictionary* obj = models[indexPath.row];
  66. //NSLog(@"------>%@",obj);
  67. //设置图片大小不变 超出部分截掉
  68. //UIViewContentModeCenter
  69. cell.headImg.contentMode = UIViewContentModeScaleAspectFill;
  70. cell.headImg.clipsToBounds = YES;
  71. NSString *imgPath = obj[@"IMG"];
  72. if (!imgPath) {
  73. imgPath = @"";
  74. }
  75. [cell.headImg sd_setImageWithURL:[NSURL URLWithString:imgPath] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]];
  76. cell.titleLabel.text = obj[@"TITLE"];
  77. cell.dateLabel.text = obj[@"CRDATE"];
  78. if ([obj[@"CRDATE"] length] > 10) {
  79. cell.dateLabel.text = [obj[@"CRDATE"] substringToIndex:10];
  80. }
  81. if ([obj[@"CRDATE"] isEqualToString:@""]) {
  82. cell.dateLabel.text = @"摘自网络";
  83. }
  84. cell.watchLabel.text = [NSString stringWithFormat:@"阅读:%@",obj[@"READNUM"]];
  85. return cell;
  86. }
  87. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  88. {
  89. return models.count;
  90. }
  91. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  92. {
  93. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  94. NewsDetVC* vc = [[NewsDetVC alloc] init];
  95. [vc setPreModel:models[indexPath.row]];
  96. vc.type = @"1";
  97. [self navPushHideTabbarToVC:vc];
  98. }
  99. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  100. {
  101. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  102. return view;
  103. }
  104. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  105. {
  106. return .1;
  107. }
  108. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  109. {
  110. //查看更多
  111. CGPoint off = scrollView.contentOffset;
  112. if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  113. [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  114. [self getTopicNews];
  115. }
  116. }
  117. #pragma mark -
  118. -(void)getTopicNews
  119. {
  120. if (![Util connectedToNetWork]) {
  121. showMsgUnconnect();
  122. [holdV setHidden:YES];
  123. return;
  124. }
  125. NSMutableArray *arr=[NSMutableArray array];
  126. [arr addPro:@"isPage" Value:@"1"];
  127. [arr addPro:@"pageSize" Value:@"10"];
  128. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]];
  129. NSString* method = @"getTopicNews";
  130. [MBProgressHUD showLoadToView:self.view];
  131. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  132. [MBProgressHUD hideHUDForView:self.view];
  133. if (!dict) {
  134. ShowMsgFailed();
  135. [holdV setHidden:NO];
  136. return;
  137. }
  138. if ( [dict[@"code"] isEqualToString:@"1"]) {
  139. ShowMsg(dict[@"body"]);
  140. [holdV setHidden:NO];
  141. return;
  142. }
  143. NSArray* resArr = dict[@"body"];
  144. if (resArr.count) {
  145. [models addObjectsFromArray:resArr];
  146. currentPage ++;
  147. //NSLog(@"%d,--------->%@",currentPage,models);
  148. //要放在主线程改变UI
  149. [myTableView reloadData];
  150. }
  151. [holdV setHidden:models.count ];
  152. }];
  153. }
  154. @end