123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- //
- // ShareVC.m
- // jiaPei
- //
- // Created by apple on 16/4/11.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "ShareVC.h"
- #import "HolderView.h"
- #import "newDetailVC.h"
- #import "NewListNoImg.h"
- #import "NewsDetVC.h"
- #import "Tools.h"
- @interface ShareVC ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSArray *superMenu;
- NSArray *childMenu;
- NSString *selectID;
- NSString *searchID;
- NSInteger lastID;
- NSInteger currentPage;
- NSMutableArray *newsList;
- BOOL isChild;
-
- UILabel *lineLabel;
- UILabel *childMenuLabel;
- UILabel *holderLabel;
- UIView *childView;
- UIScrollView *supMenuScroll;
- UITableView *mainTableView;
- UITableView *childTableView;
- HolderView *placeHolder;
- }
- @end
- @implementation ShareVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationController.navigationBar.backgroundColor = backGroundColor;
- self.navigationController.navigationBar.translucent = NO;
- self.view.backgroundColor = [UIColor whiteColor];
- self.title = @"驾考新闻";
- [self configNavigationBar];
-
- newsList = [NSMutableArray array];
- searchID = @"1";
- selectID = @"1";
- currentPage = 1;
- lastID = 1;
- [self getNewsItemByPidAndTypeWithID:@"0"];
- }
- -(void)creatMainUI
- {
- //只是为了让第一个为滑动视图的时候不偏移 那这样的话 以前的demo应该都可以用 之前虐了自己那么久的东西 以后就这样解决吧
- UIView *firstView = [UIView new];
- [self.view addSubview:firstView];
-
- supMenuScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 46 )];
- supMenuScroll.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1];
-
- UIButton *btn = nil;
- CGFloat wid = 85;
- for (int i = 0; i < superMenu.count; i++)
- {
- NSDictionary *dic = superMenu[i];
- btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(wid*i, 0, wid, 46);
- if (i == superMenu.count-1) {
- btn.width += 10;
- }
-
- [btn setTitle:dic[@"NAME"] textColor:kTitleColor font:Font17 fotState:UIControlStateNormal];
- [btn setTitle:dic[@"NAME"] textColor:defGreen font:Font17 fotState:UIControlStateSelected];
- btn.titleLabel.font = [UIFont systemFontOfSize:17];
- btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- if (i == 0)
- {
- btn.selected = YES;
- }
- [btn target:self tag:i + 1];
- [supMenuScroll addSubview:btn];
- }
- lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 44, 75, 2)];
- [lineLabel setBackgroundColor:defGreen];
- [supMenuScroll addSubview:lineLabel];
- [supMenuScroll setShowsHorizontalScrollIndicator:NO];
- supMenuScroll.contentSize = CGSizeMake(superMenu.count * wid + 10, 46);
- [self.view addSubview:supMenuScroll];
-
-
- CGFloat x,y,w,h;
- x = 0;
- y = 46;
- w = kSize.width;
- h = 40;
- UIView *childMenuBar = [[UIView alloc] setxywh];
- [childMenuBar borderColor:KlineColor width:1 cornorRadios:0];
- childMenuBar.backgroundColor = backGroundColor;
- [self.view addSubview:childMenuBar];
-
- y = 0;
- w = 80;
- UIButton *allBtn = [[UIButton alloc] setxywh];
- [allBtn setImage:[UIImage imageNamed:@"news_all"] withTitle:@"全部" forState:UIControlStateNormal];
- allBtn.titleLabel.font = [UIFont systemFontOfSize:15];
- [allBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [allBtn setImageEdgeInsets:UIEdgeInsetsMake(0, allBtn.titleLabel.width + allBtn.imageView.width, 0, -allBtn.titleLabel.width - allBtn.imageView.width)];
- [allBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -allBtn.imageView.width, 0, allBtn.imageView.width)];
- [allBtn addTarget:self action:@selector(openChildMenu) forControlEvents:UIControlEventTouchUpInside];
- [childMenuBar addSubview:allBtn];
-
- x += 80;
- w = kSize.width - 80;
- childMenuLabel = [[UILabel alloc] setxywh];
- childMenuLabel.font = [UIFont systemFontOfSize:15];
- childMenuLabel.textColor = contentTextColor;
- [childMenuBar addSubview:childMenuLabel];
-
-
- x = 0;
- y = 86;
- w = kSize.width;
- h = kSize.height - y - kNavOffSet;
- mainTableView = [[UITableView alloc] setxywh style:UITableViewStylePlain];
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- mainTableView.tag = 1;
-
- mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
- [self.view addSubview:mainTableView];
-
- placeHolder = [[HolderView alloc] initWithFrame:mainTableView.frame];
- [placeHolder freshBlock:^{
-
- currentPage = 1;
- [self getNewsInfoByItemId];
- }];
- [self.view addSubview:placeHolder];
-
-
- //子菜单写在这里 在下边只要做位置的变动就好了
- x = kSize.width;
- childView = [[UIView alloc] setxywh];
- childView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.1];
- [self.view addSubview:childView];
-
- w = kSize.width/3.0;
- childTableView = [[UITableView alloc] initWithFrame:CGRectMake(w, 0, 2*w, h) style:UITableViewStylePlain];
- childTableView.delegate = self;
- childTableView.dataSource = self;
- childTableView.tag = 2;
- [childView addSubview:childTableView];
-
- holderLabel = [[UILabel alloc] initWithFrame:CGRectMake(w, 20, 2*w, 50)];
- [holderLabel setText:@"暂无数据" Font:20 TextColor:contentTextColor Alignment:NSTextAlignmentCenter];
- [childView addSubview:holderLabel];
-
-
- //默认显示新闻
- [self getNewsInfoByItemId];
- }
- -(void)btnClick:(UIButton *)sender
- {
- //NSLog(@"tag---->%d",(int)sender.tag);
-
- //在这里把下面处理下
- childMenuLabel.text = @"";
- //说明屏幕有二级菜单
- if (childView.x < 100) {
- [UIView animateWithDuration:.5 animations:^{
-
- isChild = NO;
- childView.x = kSize.width;
- childView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.1];
- }];
- }
-
- //改变按钮的状态
- UIButton *lastBtn = (UIButton *)[supMenuScroll viewWithTag:lastID];
- lastBtn.selected = NO;
- sender.selected = YES;
- lastID = sender.tag;
-
- //移动按钮下的线
- NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:sender.titleLabel.font,NSFontAttributeName, nil];
- float width= [[superMenu[sender.tag - 1] objectForKey:@"NAME"] sizeWithAttributes:dic].width;
- [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:.3];
- lineLabel.bounds=CGRectMake(0, 0, width, 2);
- lineLabel.center=CGPointMake(sender.center.x, lineLabel.center.y);
- [UIView commitAnimations];
-
- NSDictionary *menuDic = superMenu[sender.tag - 1];
- selectID = menuDic[@"ID"];
- placeHolder.hidden = NO;
- currentPage = 1;
- searchID = selectID;
- [self getNewsInfoByItemId];
- }
- -(void)openChildMenu
- {
- if (isChild) {
- return;
- }
- isChild = YES;
- holderLabel.hidden = NO;
- childMenu = [NSArray array];
- [childTableView reloadData];
- [self getNewsItemByPidAndTypeWithID:selectID];
- [UIView animateWithDuration:.5 animations:^{
-
- childView.x = 0;
- childView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.8];
- }];
-
- }
- #pragma mark 异步获取新闻栏目
- -(void)getNewsItemByPidAndTypeWithID:(NSString *)pid
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"pid" Value:pid];
-
- NSString* method = @"getNewsItemByPidAndType";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view];
- if (!root)
- {
- [LoadingView showMsg:@"网络请求失败!"];
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
- if ([root[@"body"] count] < 1) {
- //ShowMsg(@"暂无数据");
- return;
- }
-
- if ([pid isEqualToString:@"0"]) {
-
- superMenu = root[@"body"];
-
- [self creatMainUI];
- }else{
-
- //将‘全部’按钮插进去
- childMenu = root[@"body"];
- NSMutableArray *array = [NSMutableArray arrayWithArray:childMenu];
- NSDictionary *superData = @{@"ID":selectID,@"NAME":@"全部",@"PID":@"0",@"TYPE":@"0"};
- [array insertObject:superData atIndex:0];
-
- childMenu = [NSArray arrayWithArray:array];
-
- if (childMenu.count == 0) {
- holderLabel.hidden = NO;
- }else{
- holderLabel.hidden = YES;
- [childTableView reloadData];
- }
- }
- }];
- }
- #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 (!root)
- {
- [LoadingView showMsg:@"网络请求失败!"];
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- }
-
- 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
- {
- if (tableView.tag == 1) {
- return newsList.count;
- }else{
- return childMenu.count;
- }
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.tag == 2) {
-
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sysCell"];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"sysCell"];
- }
- NSDictionary *dic = childMenu[indexPath.row];
- cell.textLabel.text = dic[@"NAME"];
- return cell;
- }
-
- NSDictionary* dic = newsList[indexPath.row];
- //NSLog(@"------>%@",dic);
-
- 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.contentLabel.text = [NSString stringWithFormat:@" %@",[dic[@"REMARK"] stringByReplacingOccurrencesOfString:@"&" withString:@""]];
-
- 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"]]];
-
- return cell;
- }else{
-
- newDetailVC *cell = [tableView dequeueReusableCellWithIdentifier:@"newCell"];
- if (cell == nil)
- {
- NSArray * viewArray = [[NSBundle mainBundle] loadNibNamed:@"newDetailVC" owner:nil options:nil];
- cell = [viewArray firstObject];
- }
-
- //设置图片大小不变 超出部分截掉
- //UIViewContentModeCenter
- 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.contentLabel.text = [NSString stringWithFormat:@" %@",[dic[@"REMARK"] stringByReplacingOccurrencesOfString:@"&" withString:@""]];
- 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"]]];
-
- return cell;
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.tag == 2) {
- return 50;
- }
- 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];
-
- if (tableView.tag == 2) {
-
- NSDictionary *dic = childMenu[indexPath.row];
- currentPage = 1;
- searchID = dic[@"ID"];
- childMenuLabel.text = dic[@"NAME"];
- if ([dic[@"NAME"] isEqualToString:@"全部"]) {
- childMenuLabel.text = @"";
- }
- [self getNewsInfoByItemId];
-
- [UIView animateWithDuration:.5 animations:^{
-
- isChild = NO;
- childView.x = kSize.width;
- childView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.1];
- }];
- return;
- }
-
- 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
|