123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- //
- // GuideHtmlVC.m
- // jiaPei
- //
- // Created by apple on 16/4/29.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "GuideHtmlVC.h"
- #import "HolderView.h"
- #import "newDetailVC.h"
- #import "NewListNoImg.h"
- #import "NewsDetVC.h"
- #import "Tools.h"
- @interface GuideHtmlVC ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSInteger currentPage;
- NSMutableArray *newsList;
- UITableView *mainTableView;
- HolderView *placeHolder;
- }
- @end
- @implementation GuideHtmlVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationController.navigationBar.backgroundColor = backGroundColor;
- self.view.backgroundColor = [UIColor whiteColor];
- [self configNavigationBar];
-
- newsList = [NSMutableArray array];
- currentPage = 1;
-
- CGFloat x,y,w,h;
- x = 0;
- y = 0;
- w = kSize.width;
- h = kSize.height - kNavOffSet;
- mainTableView = [[UITableView alloc] setxywh style:UITableViewStylePlain];
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:mainTableView];
-
- placeHolder = [[HolderView alloc] initWithFrame:mainTableView.frame];
- [placeHolder freshBlock:^{
-
- currentPage = 1;
- [self getNewsInfoByItemId];
- }];
- [self.view addSubview:placeHolder];
-
- //默认显示新闻
- [self getNewsInfoByItemId];
- }
- #pragma mark 异步获取新闻列表
- -(void)getNewsInfoByItemId
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"itemId" Value:_searchID];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"10"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
-
- NSString* method = @"getNewsInfoByItemId";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- [MBProgressHUD hideHUDForView:self.view];
- //NSLog(@"getNewsInfoByItemId---%@--->%@",arr,root);
-
- if (newsList.count > 0) {
- placeHolder.hidden = YES;
- }else {
- placeHolder.hidden = NO;
- }
-
- if (!root)
- {
- [LoadingView showMsg:@"网络请求失败!"];
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
-
- if ([root[@"body"] count] < 1) {
- ShowMsg(@"已加载全部");
- return;
- }
-
- if (currentPage == 1) {
-
- newsList = [NSMutableArray arrayWithArray:root[@"body"]];
- }else{
- [newsList addObjectsFromArray:root[@"body"]];
- }
-
- currentPage ++;
- placeHolder.hidden = YES;
- [mainTableView reloadData];
- }];
-
- }
- #pragma mark maintableView delegate
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return newsList.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary* dic = newsList[indexPath.row];
-
- if ([dic[@"ISIMG"] isEqualToString:@"0"]) {
-
- NewListNoImg *cell = [tableView dequeueReusableCellWithIdentifier:@"newNoImg"];
- if (cell == nil)
- {
- NSArray * viewArray = [[NSBundle mainBundle] loadNibNamed:@"NewListNoImg" owner:nil options:nil];
- cell = [viewArray firstObject];
- }
-
- cell.titleLabel.text = dic[@"TITLE"];
- // if ([dic[@"LIGHT"] isEqualToString:@"0"]) {
- // cell.titleLabel.textColor = kTitleColor;
- // }else{
- // cell.titleLabel.textColor = [UIColor redColor];
- // }
- cell.dateLabel.text = dic[@"ADDTIME"];
- if ([dic[@"ADDTIME"] length] > 10) {
- cell.dateLabel.text = [dic[@"ADDTIME"] substringToIndex:10];
- }
- if ([dic[@"ADDTIME"] isEqualToString:@""]) {
- cell.dateLabel.text = @"摘自网络";
- }
- cell.countLabel.text = [NSString stringWithFormat:@"阅读:%@",[Tools isWan:dic[@"READNUM"]]];
-
-
- if ([dic[@"REMARK"] length] > 0) {
- cell.contentLabel.text = [NSString stringWithFormat:@" %@",[dic[@"REMARK"] stringByReplacingOccurrencesOfString:@"&" withString:@""]];
- }
-
- return cell;
- }else{
-
- newDetailVC *cell = [tableView dequeueReusableCellWithIdentifier:@"newCell"];
- if (cell == nil)
- {
- NSArray * viewArray = [[NSBundle mainBundle] loadNibNamed:@"newDetailVC" owner:nil options:nil];
- cell = [viewArray firstObject];
- }
-
- //设置图片大小不变 超出部分截掉
- cell.headImg.contentMode = UIViewContentModeScaleAspectFill;
- cell.headImg.clipsToBounds = YES;
-
- //dansonimg
- [cell.headImg sd_setImageWithURL:[NSURL URLWithString:dic[@"IMGPATH"]] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]];
-
- //设置标题及标题颜色
- cell.titleLabel.text = dic[@"TITLE"];
- // if ([dic[@"LIGHT"] isEqualToString:@"0"]) {
- // cell.titleLabel.textColor = kTitleColor;
- // }else{
- // cell.titleLabel.textColor = [UIColor redColor];
- // }
-
- cell.sourceLabel.text = dic[@"ADDTIME"];
- if ([dic[@"ADDTIME"] length] > 10) {
- cell.sourceLabel.text = [dic[@"ADDTIME"] substringToIndex:10];
- }
- if ([dic[@"ADDTIME"] isEqualToString:@""]) {
- cell.sourceLabel.text = @"摘自网络";
- }
- cell.readCount.text = [NSString stringWithFormat:@"阅读:%@",[Tools isWan:dic[@"READNUM"]]];
-
- if ([dic[@"REMARK"] length] > 0) {
- cell.contentLabel.text = [NSString stringWithFormat:@" %@",[dic[@"REMARK"] stringByReplacingOccurrencesOfString:@"&" withString:@""]];
- }
-
- return cell;
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary *dic = newsList[indexPath.row];
- if ([dic[@"ISIMG"] isEqualToString:@"0"]) {
- return 110;
- }else{
- return 130;
- }
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- NSDictionary *dic = newsList[indexPath.row];
-
- NewsDetVC* vc = [[NewsDetVC alloc] init];
- vc.preModel = dic;
- vc.type = @"3";
- [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
- {
- //NSLog(@"%d",(int)scrollView.tag);
-
- if (scrollView.tag == 2) {
- return;
- }
-
- 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 getNewsInfoByItemId];
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|