LVCTelevisioController.m
3.82 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
//
// LVCTelevisioController.m
// LiveVideoCloud
//
// Created by iOS on 2017/6/27.
// Copyright © 2017年 cnlive. All rights reserved.
//
#import "LVCTelevisioController.h"
#import "LVCTelevisionModel.h"
#import "LVCTelevisionCell.h"
#import "LVCLivePlayerController.h"
@interface LVCTelevisioController ()<UITableViewDelegate, UITableViewDataSource>
{
NSMutableArray *_channelsModelArray; //数据源
}
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation LVCTelevisioController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = @"直播";
_channelsModelArray = [[NSMutableArray alloc] init];
[self.view addSubview:self.tableView];
[self loadData];
}
- (void)loadData {
//demo使用的是本地数据
NSString *path = [[NSBundle mainBundle] pathForResource:@"TelevisionData" ofType:@"json"];
NSData *data=[NSData dataWithContentsOfFile:path];
NSError *error;
id responseObject=[NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments
error:&error];
for (NSDictionary *dataDic in responseObject) {
LVCTelevisionModel *model = [LVCTelevisionModel mj_objectWithKeyValues:dataDic];
[_channelsModelArray addObject:model];
}
[_tableView reloadData];
}
#pragma mark -
#pragma mark - UITableviewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _channelsModelArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return SCREEN_WIDTH*9/16+40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"LVCTelevisionCell";
LVCTelevisionCell *cell = [[LVCTelevisionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
if (!cell) {
cell = [tableView dequeueReusableCellWithIdentifier:cellId];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
LVCTelevisionModel *model = [_channelsModelArray objectAtIndex:indexPath.row];
cell.model = model;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
LVCTelevisionModel *model = _channelsModelArray[indexPath.row];
self.hidesBottomBarWhenPushed = YES;
LVCLivePlayerController *playVC = [[LVCLivePlayerController alloc] init];
playVC.model = model;
self.navigationController.navigationBar.hidden = YES;
[self.navigationController pushViewController:playVC animated:YES];
self.hidesBottomBarWhenPushed = NO;
}
#pragma mark -
#pragma mark - getter
- (UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-49-64) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
}
return _tableView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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.
}
*/
@end