CNHomeRightViewController.m 7.26 KB
//
//  CNHomeRightViewController.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/18.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNHomeRightViewController.h"
#import "CNHomeRightTableViewCell.h"
#import "CNHomeRightHeaderFooterView.h"
#import "XLSlideMenu.h"
#import "CNLiveSearchViewController.h"//搜索
#import <KJARLib/KJARSCanViewController.h>

@interface CNHomeRightViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *data;

@end

@implementation CNHomeRightViewController
static NSString *homeRightTableViewCell = @"CNHomeRightTableViewCell";
static NSString *homeRightHeaderFooterView = @"CNHomeRightHeaderFooterView";

#pragma mark - Data
- (void)getData:(NSNotification *)noti{
    NSLog(@"%@",noti.userInfo);
    NSDictionary *dic = [noti userInfo];
    self.data = [dic objectForKey:@"titles"];
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getData:) name:@"CNHomeRightViewController" object:nil];
    
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40.f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.f;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001f;
    
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
    
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 0;
        
    }else if (section == 1){
        return self.data.count;
        
    }else{
        return 0;

    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSArray *array = @[@"外文宣言", @"答记者问", @"国新视角", @"一带一路"];
    CNHomeRightTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:homeRightTableViewCell];
    if (!cell) {
        cell = [[CNHomeRightTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:homeRightTableViewCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.title = self.data[indexPath.row];
    return cell;
    
}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    if ([view isMemberOfClass:[UITableViewHeaderFooterView class]]) {
        ((UITableViewHeaderFooterView *)view).backgroundView.backgroundColor = [UIColor whiteColor];
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    NSArray *array = @[@"搜索内容", @"栏目列表", @"AR扫描"];
    
    CNHomeRightHeaderFooterView *sectionHeadView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:homeRightHeaderFooterView];
    if(!sectionHeadView){
        sectionHeadView = [[CNHomeRightHeaderFooterView alloc] initWithReuseIdentifier:homeRightHeaderFooterView];
    }
    sectionHeadView.title = array[section];
    if(section == 0){
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickedSearch)];
        [sectionHeadView addGestureRecognizer:tap];
    }else if (section == 2){
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickedKJARSCan)];
        [sectionHeadView addGestureRecognizer:tap];
    }

    return sectionHeadView;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    XLSlideMenu *menu = (XLSlideMenu *)self.parentViewController;
    CNLiveTabBarController *liveTab = (CNLiveTabBarController *)menu.rootViewController;
    CNLiveBaseNavigationController *controllers = liveTab.viewControllers[0];
    CNHomeViewController *vc = controllers.viewControllers[0];
    vc.segmentControl.current = indexPath.row;
    [menu showRootViewControllerAnimated:true];

}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - Action
//搜索
- (void)clickedSearch{
    XLSlideMenu *vc = (XLSlideMenu *)self.parentViewController;
    //
    CNLiveTabBarController *liveTab = (CNLiveTabBarController *)vc.rootViewController;
    CNLiveBaseNavigationController *controllers = liveTab.viewControllers[0];
    CNLiveSearchViewController *search = [[CNLiveSearchViewController alloc]init];
    search.hidesBottomBarWhenPushed = YES;
    [controllers pushViewController:search animated:YES];
    [vc showRootViewControllerAnimated:true];

}

- (void)clickedKJARSCan{
    // 判断网络状态
    if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
        [AlertViewTool showHUDViewText:@"您未连接网络,请联网后重试!"];
        return;
    }
    
    XLSlideMenu *vc = (XLSlideMenu *)self.parentViewController;
    CNLiveTabBarController *liveTab = (CNLiveTabBarController *)vc.rootViewController;
    CNLiveBaseNavigationController *controllers = liveTab.viewControllers[0];
    KJARSCanViewController *scanView = [[KJARSCanViewController alloc]init];
    [scanView SetAccountKey:@"AP6caf76bc2c5f45698c74ef7e126703e1" :@"3f57c704ff9f4c8d82a575db5c7abe12"];
    scanView.hidesBottomBarWhenPushed = YES;
    [controllers pushViewController:scanView animated:YES];
    [vc showRootViewControllerAnimated:true];
    
}
#pragma mark - Lazy Laoding
- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, MainScreenWidth*0.5, MainScreenHeight-NavBarHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.scrollEnabled = NO;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        
        [_tableView registerClass:[CNHomeRightTableViewCell class] forCellReuseIdentifier:homeRightTableViewCell];
        [_tableView registerClass:[CNHomeRightHeaderFooterView class] forHeaderFooterViewReuseIdentifier:homeRightHeaderFooterView];
        
    }
    return _tableView;
}

- (NSArray *)data{
    if(!_data){
        _data = [[NSArray alloc] init];
    }
    return _data;
}
- (BOOL)shouldAutorotate{
    return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    
}

@end