LVCTelevisioController.m 3.12 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"

@interface LVCTelevisioController ()<UITableViewDelegate, UITableViewDataSource>
{
    NSMutableArray *_channelsModelArray;
}

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation LVCTelevisioController

- (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 {

    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];
    }
    LVCTelevisionModel *model = [_channelsModelArray objectAtIndex:indexPath.row];
    cell.model = model;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

#pragma mark -
#pragma mark - getter
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-49) 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