SchoolNewsVC.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // SchoolNewsVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/1/27.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "SchoolNewsVC.h"
  9. #import "NewsDetVC.h"
  10. #import "HolderView.h"
  11. @interface SchoolNewsVC ()<UITableViewDataSource,UITableViewDelegate>
  12. {
  13. NSArray *newsArray;
  14. UITableView *mainTable;
  15. HolderView* holdV;
  16. }
  17. @end
  18. @implementation SchoolNewsVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.title = @"驾校新闻";
  22. self.view.backgroundColor = backGroundColor;
  23. [self configNavigationBar];
  24. newsArray = [NSArray array];
  25. [self getnewsList];
  26. [self myInit];
  27. }
  28. -(void)myInit
  29. {
  30. mainTable = [[UITableView alloc] initWithFrame:kFrame];
  31. mainTable.height -= kNavOffSet;
  32. mainTable.delegate = self;
  33. mainTable.dataSource = self;
  34. mainTable.estimatedSectionFooterHeight = 0;
  35. [self.view addSubview:mainTable];
  36. holdV = [[HolderView alloc] initWithFrame:mainTable.frame];
  37. [holdV freshBlock:^{
  38. [self getnewsList];
  39. }];
  40. [self.view addSubview:holdV];
  41. [holdV setHidden:YES];
  42. }
  43. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  44. {
  45. return newsArray.count;
  46. }
  47. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  48. {
  49. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  50. if (cell == nil)
  51. {
  52. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  53. }
  54. NSDictionary *dic = newsArray[indexPath.row];
  55. cell.textLabel.text = [NSString stringWithFormat:@"%d、%@ %@",(int)indexPath.row + 1,dic[@"GROUPNAME"],dic[@"TITLE"]];
  56. NSString *string = [NSString stringWithFormat:@"%d、%@ %@",(int)indexPath.row + 1,dic[@"GROUPNAME"],dic[@"TITLE"]];
  57. NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d、%@ %@",(int)indexPath.row + 1,dic[@"GROUPNAME"],dic[@"TITLE"]]];
  58. NSRange sub = [string rangeOfString:@" "];
  59. [str addAttribute:NSForegroundColorAttributeName value:defGreen range:NSMakeRange(0,sub.location)];
  60. cell.textLabel.attributedText = str;
  61. return cell;
  62. }
  63. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  64. {
  65. NewsDetVC* vc = [[NewsDetVC alloc] init];
  66. [vc setPreModel:newsArray[indexPath.row]];
  67. vc.type = @"2";
  68. [self navPushHideTabbarToVC:vc];
  69. }
  70. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  71. {
  72. return .1;
  73. }
  74. -(void)getnewsList
  75. {
  76. [holdV setHidden:0];
  77. if (![Util connectedToNetWork]) {
  78. showMsgUnconnect();
  79. return;
  80. }
  81. NSMutableArray *arr=[NSMutableArray array];
  82. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:self.jxbh,@"jxbh", nil]];
  83. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"" ,@"isPage", nil]];
  84. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"" ,@"pageSize", nil]];
  85. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"" ,@"currentPage", nil]];
  86. //NSLog(@"新闻--%@",arr);驾校新闻 应该做个分页的 但是这里不想 等后期数据够多再加 dansonmark
  87. NSString* method = @"getNewsInfoByJxbh";
  88. [MBProgressHUD showLoadToView:self.view];
  89. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  90. [MBProgressHUD hideHUDForView:self.view];
  91. if (!root)
  92. {
  93. ShowMsgFailed();
  94. return;
  95. }
  96. NSString* code = root[@"code"];
  97. if ( 1 == code.intValue ) {
  98. ShowMsgFailed();
  99. return;
  100. }
  101. NSArray* news = root[@"body"];
  102. //NSLog(@"获取到的新闻列表---->%@",news);
  103. newsArray = news;
  104. [holdV setHidden:newsArray.count];
  105. [mainTable reloadData];
  106. }];
  107. }
  108. - (void)didReceiveMemoryWarning {
  109. [super didReceiveMemoryWarning];
  110. // Dispose of any resources that can be recreated.
  111. }
  112. @end