CNHomeRightViewController.m
7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
// 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 2;
}
#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 = @[@"搜索内容", @"栏目列表"];
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