// // SchoolNewsVC.m // jiaPei // // Created by apple on 16/1/27. // Copyright © 2016年 JCZ. All rights reserved. // #import "SchoolNewsVC.h" #import "NewsDetVC.h" #import "HolderView.h" @interface SchoolNewsVC () { NSArray *newsArray; UITableView *mainTable; HolderView* holdV; } @end @implementation SchoolNewsVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"驾校新闻"; self.view.backgroundColor = backGroundColor; [self configNavigationBar]; newsArray = [NSArray array]; [self getnewsList]; [self myInit]; } -(void)myInit { mainTable = [[UITableView alloc] initWithFrame:kFrame]; mainTable.height -= kNavOffSet; mainTable.delegate = self; mainTable.dataSource = self; mainTable.estimatedSectionFooterHeight = 0; [self.view addSubview:mainTable]; holdV = [[HolderView alloc] initWithFrame:mainTable.frame]; [holdV freshBlock:^{ [self getnewsList]; }]; [self.view addSubview:holdV]; [holdV setHidden:YES]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return newsArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } NSDictionary *dic = newsArray[indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@"%d、%@ %@",(int)indexPath.row + 1,dic[@"GROUPNAME"],dic[@"TITLE"]]; NSString *string = [NSString stringWithFormat:@"%d、%@ %@",(int)indexPath.row + 1,dic[@"GROUPNAME"],dic[@"TITLE"]]; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d、%@ %@",(int)indexPath.row + 1,dic[@"GROUPNAME"],dic[@"TITLE"]]]; NSRange sub = [string rangeOfString:@" "]; [str addAttribute:NSForegroundColorAttributeName value:defGreen range:NSMakeRange(0,sub.location)]; cell.textLabel.attributedText = str; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NewsDetVC* vc = [[NewsDetVC alloc] init]; [vc setPreModel:newsArray[indexPath.row]]; vc.type = @"2"; [self navPushHideTabbarToVC:vc]; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(void)getnewsList { [holdV setHidden:0]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:self.jxbh,@"jxbh", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"" ,@"isPage", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"" ,@"pageSize", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"" ,@"currentPage", nil]]; //NSLog(@"新闻--%@",arr);驾校新闻 应该做个分页的 但是这里不想 等后期数据够多再加 dansonmark NSString* method = @"getNewsInfoByJxbh"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsgFailed(); return; } NSString* code = root[@"code"]; if ( 1 == code.intValue ) { ShowMsgFailed(); return; } NSArray* news = root[@"body"]; //NSLog(@"获取到的新闻列表---->%@",news); newsArray = news; [holdV setHidden:newsArray.count]; [mainTable reloadData]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end