123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //
- // 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 ()<UITableViewDataSource,UITableViewDelegate>
- {
- 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
|