CNMyViewController.m 9.47 KB
//
//  CNMyViewController.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/18.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNMyViewController.h"
#import "CNMyTableViewHeaderView.h"
#import "CNMyTableViewCell.h"

#import "CNMyAnnouncementsViewController.h"//通知公告
#import "CNLiveSettingViewController.h"//设置
#import "CNLiveContactUsViewController.h"//联系我们
#import "CNLiveMyCollectionViewController.h"
#import "CNLiveCertificatesViewController.h"
#import "CNLiveUserSettingViewController.h"//用户设置

@interface CNMyViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSArray *pics;

@end

@implementation CNMyViewController
static NSString *identifier = @"CNMyTableViewCell";
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIImage *backGroundImage = [UIImage imageNamed:@"cnlive_headerBack"];

    backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
    [self.navigationController.navigationBar setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];

    self.name = CustomStr(@"PersonalCenter");
    [self.view addSubview:self.tableView];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLanguageVersion:) name:@"changeLanguageVersion" object:nil];

}
- (void)changeLanguageVersion:(NSNotification *)notification {
    self.name = CustomStr(@"PersonalCenter");
    [self.tableView reloadData];
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeLanguageVersion" object:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.00000001f;

}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titles.count;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *data = self.titles[section];
    return data.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    NSArray *name = @[@[CustomStr(@"Announcements"), CustomStr(@"MyFavorite")],@[CustomStr(@"ContactUs")],@[CustomStr(@"Settings")]];
//    NSArray *pic = @[@[@"cnlive_my_news", @"cnlive_my_collection"],@[@"cnlive_my_tel"],@[@"cnlive_my_setting"]];
    
    CNMyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[CNMyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.name = self.titles[indexPath.section][indexPath.row];
    cell.pic = self.pics[indexPath.section][indexPath.row];

    return cell;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MainScreenWidth, 10)];
    headerView.backgroundColor = HEXCOLOR(0xebebeb);
    return headerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MainScreenWidth, 0.00000001f)];
    footerView.backgroundColor = HEXCOLOR(0xebebeb);
    return footerView;
}

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

    if(indexPath.section == 0){
        if(indexPath.row == 0){
            //通知公告
            CNMyAnnouncementsViewController *vc = [CNMyAnnouncementsViewController new];
            vc.navTitle = CustomStr(@"Announcements");
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else if (indexPath.row == 1){
            //我的收藏
            CNLiveMyCollectionViewController *vc = [CNLiveMyCollectionViewController new];
            vc.navTitle = CustomStr(@"MyFavorite");
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
        return;
       
    }else if (indexPath.section == 1){
        if(indexPath.row == 0){
            //证件申领
//            CNLiveCertificatesViewController *vc = [CNLiveCertificatesViewController new];
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:vc animated:YES];
//            CNLiveWebViewController *vc = [CNLiveWebViewController new];
//            vc.navTitle = CustomStr(@"Certificates");
//            vc.url = @"http://219.142.85.77/index.html";
//            vc.navTitle = CustomStr(@"Certificates");
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:vc animated:YES];
            
            CNLiveContactUsViewController *vc = [CNLiveContactUsViewController new];
            vc.navTitle = CustomStr(@"ContactUs");
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
            
        }else if (indexPath.row == 1){
            //联系我们
//            CNLiveContactUsViewController *vc = [CNLiveContactUsViewController new];
//            vc.navTitle = CustomStr(@"ContactUs");
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:vc animated:YES];
            
        }
        return;
        
    }else if (indexPath.section == 2){
        //设置
        CNLiveSettingViewController *vc = [CNLiveSettingViewController new];
        vc.navTitle = CustomStr(@"Settings");
        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:UITableViewStyleGrouped];
        _tableView.scrollEnabled = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = HEXCOLOR(0xebebeb);
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        
        CNMyTableViewHeaderView *headerView = [[CNMyTableViewHeaderView alloc]initWithFrame:CGRectMake(0, 0, MainScreenWidth, 150)];
        headerView.backgroundColor = Color_Blue;
        headerView.block = ^{
            if ([[ZXWUserInformation shareZXWUserInformation] isLogin]){
                CNLiveUserSettingViewController *vc = [CNLiveUserSettingViewController new];
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            }else{
                CNLiveLoginViewController *vc = [CNLiveLoginViewController new];
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            }
            
        };
        _tableView.tableHeaderView = headerView;
        
        [_tableView registerClass:[CNMyTableViewCell class] forCellReuseIdentifier:identifier];

    }
    return _tableView;
}

//    NSArray *name = @[@[@"通知公告", @"我的收藏"],@[@"证件申领", @"联系我们"],@[@"设置"]];
//    NSArray *name = @[@[CustomStr(@"Announcements"), CustomStr(@"MyFavorite")],@[CustomStr(@"Certificates"), CustomStr(@"ContactUs")],@[CustomStr(@"Settings")]];
//    NSArray *pic = @[@[@"cnlive_my_news", @"cnlive_my_collection"],@[@"cnlive_my_certificate", @"cnlive_my_tel"],@[@"cnlive_my_setting"]];

- (NSArray *)titles{
    if(!_titles){
        NSArray *name = @[@[CustomStr(@"Announcements"), CustomStr(@"MyFavorite")],@[CustomStr(@"ContactUs")],@[CustomStr(@"Settings")]];
        _titles = [[NSArray alloc] initWithArray:name];
    }
    return _titles;
}
- (NSArray *)pics{
    if(!_pics){
        NSArray *pic = @[@[@"cnlive_my_news", @"cnlive_my_collection"],@[@"cnlive_my_tel"],@[@"cnlive_my_setting"]];
        _pics = [[NSArray alloc] initWithArray:pic];

    }
    return _pics;
}

@end