// // NewsOfLearnVC.m // jiaPei // // Created by apple on 15/12/8. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "NewsOfLearnVC.h" #import "HolderView.h" #import "NewsDetVC.h" #import "NewsOfLearnCell.h" @interface NewsOfLearnVC () { UITableView* myTableView; HolderView* holdV; NSMutableArray* models; int currentPage; } @end @implementation NewsOfLearnVC - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self getTopicNews]; } #pragma mark - -(void)myInit { [self configNavigationBar]; [self setTitle:@"驾考头条"]; [self.view setBackgroundColor:[UIColor whiteColor]]; currentPage = 1; models = [NSMutableArray array]; holdV = [[HolderView alloc] initWithFrame:kFrame]; [self.view addSubview:holdV]; [holdV setHidden:YES]; [holdV freshBlock:^{ [self getTopicNews]; }]; UITableView* tv = [[UITableView alloc] initWithFrame:kFrame]; tv.height = kSize.height - kNavOffSet; tv.rowHeight = 92; tv.separatorStyle = UITableViewCellSeparatorStyleNone; [self.view addSubview:tv]; myTableView = tv; [myTableView setDelegate:self]; [myTableView setDataSource:self]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NewsOfLearnCell *cell = [tableView dequeueReusableCellWithIdentifier:@"newsCell"]; if (cell == nil) { NSArray * viewArray = [[NSBundle mainBundle] loadNibNamed:@"NewsOfLearnCell" owner:nil options:nil]; cell = [viewArray firstObject]; } NSDictionary* obj = models[indexPath.row]; //NSLog(@"------>%@",obj); //设置图片大小不变 超出部分截掉 //UIViewContentModeCenter cell.headImg.contentMode = UIViewContentModeScaleAspectFill; cell.headImg.clipsToBounds = YES; NSString *imgPath = obj[@"IMG"]; if (!imgPath) { imgPath = @""; } [cell.headImg sd_setImageWithURL:[NSURL URLWithString:imgPath] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]]; cell.titleLabel.text = obj[@"TITLE"]; cell.dateLabel.text = obj[@"CRDATE"]; if ([obj[@"CRDATE"] length] > 10) { cell.dateLabel.text = [obj[@"CRDATE"] substringToIndex:10]; } if ([obj[@"CRDATE"] isEqualToString:@""]) { cell.dateLabel.text = @"摘自网络"; } cell.watchLabel.text = [NSString stringWithFormat:@"阅读:%@",obj[@"READNUM"]]; return cell; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return models.count; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; NewsDetVC* vc = [[NewsDetVC alloc] init]; [vc setPreModel:models[indexPath.row]]; vc.type = @"1"; [self navPushHideTabbarToVC:vc]; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; return view; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { //查看更多 CGPoint off = scrollView.contentOffset; if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) { [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES]; [self getTopicNews]; } } #pragma mark - -(void)getTopicNews { if (![Util connectedToNetWork]) { showMsgUnconnect(); [holdV setHidden:YES]; return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"isPage" Value:@"1"]; [arr addPro:@"pageSize" Value:@"10"]; [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]]; NSString* method = @"getTopicNews"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { [MBProgressHUD hideHUDForView:self.view]; if (!dict) { ShowMsgFailed(); [holdV setHidden:NO]; return; } if ( [dict[@"code"] isEqualToString:@"1"]) { ShowMsg(dict[@"body"]); [holdV setHidden:NO]; return; } NSArray* resArr = dict[@"body"]; if (resArr.count) { [models addObjectsFromArray:resArr]; currentPage ++; //NSLog(@"%d,--------->%@",currentPage,models); //要放在主线程改变UI [myTableView reloadData]; } [holdV setHidden:models.count ]; }]; } @end