CNLiveMyCollectionViewController.m 7.66 KB
//
//  CNLiveMyCollectionViewController.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/21.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNLiveMyCollectionViewController.h"
#import "CNMyAnnouncementsTableViewCell.h"

#import "CNMyAnnouncementsModel.h"//cell赋值
#import "CNHomeModel.h"//跳转

@interface CNLiveMyCollectionViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *data;
@property (nonatomic, strong) NoDataView *errorLabel;


@end

@implementation CNLiveMyCollectionViewController
static NSString *myAnnouncementsTableViewCell = @"CNMyAnnouncementsTableViewCell";
#pragma mark - Data
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.data  = [[DBAction sharedDBAction] queryTable];
    self.errorLabel.hidden = self.data.count != 0;
    [self.tableView reloadData];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpNavigationBar];
    [self.view addSubview:self.tableView];
}
#pragma mark - UI
- (void)setUpNavigationBar{
    
    self.navigationController.navigationBar.barTintColor = Color_Blue;
    //左
    UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
    headerButton.layer.cornerRadius = 2.0;
    headerButton.layer.masksToBounds = true;
    [headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
    [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
    
    self.navigationItem.title = self.navTitle;
    
}
- (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.
 }
 */
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    TableData *model = self.data[indexPath.row];
    CNMyAnnouncementsModel *announcementsModel = [CNMyAnnouncementsModel mj_objectWithKeyValues:[model ToDictionary]];
    return announcementsModel.titleHeight+40;
    
}

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CNMyAnnouncementsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myAnnouncementsTableViewCell];
    if (!cell) {
        cell = [[CNMyAnnouncementsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myAnnouncementsTableViewCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    TableData *model = self.data[indexPath.row];
    CNMyAnnouncementsModel *announcementsModel = [CNMyAnnouncementsModel mj_objectWithKeyValues:[model ToDictionary]];
    cell.model = announcementsModel;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    TableData *model = self.data[indexPath.row];
    NSDictionary *_dic = [model ToDictionary];
    if ([@"program" isEqualToString:_dic[@"type"]]) {
        //视频
        OldVideoDetailViewController *vc = [[OldVideoDetailViewController alloc] initWithDictionary:_dic];
        vc.title = _dic[@"cmsColumnName"];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    } else if ([@"article" isEqualToString:_dic[@"type"]]) {
        //文章
        OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:_dic];
        vc.title = _dic[@"cmsColumnName"];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    } else if ([@"subject" isEqualToString:_dic[@"type"]]) {
        SCIOSpecialViewController *vc = [[SCIOSpecialViewController alloc] initWithDictionary:_dic];
        vc.title = @"国新专题";
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    } else if ([@"LK" isEqualToString:_dic[@"type"]]) {
        OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:_dic];
        vc.title = _dic[@"cmsColumnName"];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    
//    if ([homeModel.type isEqualToString:@"program"]) {
//        //视频
//        VideoDetailViewController *vc = [[VideoDetailViewController alloc] init];
//        vc.model = homeModel;
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//
//    } else if ([homeModel.type isEqualToString:@"article"]) {
//        //文章
//        ArticleDetailViewController *vc = [[ArticleDetailViewController alloc] init];
//        vc.model = homeModel;
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//
//    } else if ([homeModel.type isEqualToString:@"subject"]) {
//        SCIOSpecialViewController *vc = [[SCIOSpecialViewController alloc] initWithDictionary:_dic];
//        vc.title = @"国新专题";
//        vc.hidesBottomBarWhenPushed = YES;
//
//    } else if ([homeModel.type isEqualToString:@"LK"]) {
//        ArticleDetailViewController *vc = [[ArticleDetailViewController alloc] init];
//        vc.model = homeModel;
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//    }
    
}
/*
 #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

#pragma mark - Lazy Laoding
- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - NavBarHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        
        [_tableView registerClass:[CNMyAnnouncementsTableViewCell class] forCellReuseIdentifier:myAnnouncementsTableViewCell];
        
    }
    return _tableView;
}

- (NSMutableArray *)data{
    if (!_data) {
        _data = [[NSMutableArray alloc] init];

    }
    return _data;
}
- (NoDataView *)errorLabel{
    if (!_errorLabel) {
        _errorLabel = [[NoDataView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - NavBarHeight)];
        _errorLabel.title = CustomStr(@"NoData");
        [self.view addSubview:_errorLabel];
    }
    return _errorLabel;
}

@end