LVCTelevisioController.m 3.82 KB
//
//  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