IVTMyCenterViewController.m 8.21 KB
//
//  IVTMyCenterViewController.m
//  IVTMeLiveTwo
//
//  Created by XRG on 16/8/10.
//  Copyright © 2016年 QLQ. All rights reserved.
//

#import "IVTMyCenterViewController.h"
#import "IVTMyCenterTableViewCell.h"
#import "IVTMyCenterTableViewHead.h"
#import "IVTMeSupportViewController.h"
#import "IVTMyContributionListViewController.h"
#import "IVTGainsViewController.h"
#import "IVTMySettingViewController.h"
#import "IVTMyChatListViewController.h"
#import "IVTMyAccountViewController.h"
#import "IVTMyFollowListViewController.h"
#import "IVTMyFansListViewController.h"
#import "IVTMyLiveViewController.h"
#import "RealNameAuthenticationViewController.h"

@interface IVTMyCenterViewController ()<UITableViewDelegate,UITableViewDataSource,IVTMyCenterTableViewHeadDelegate>
{
    NSArray *titleDataArray;
    NSArray *imageDataArray;

    UITableView *myTableView;
    IVTMyCenterTableViewHead *headView;
}
@end

@implementation IVTMyCenterViewController

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    myTableView.contentInset = UIEdgeInsetsZero;
    myTableView.scrollIndicatorInsets = UIEdgeInsetsZero;
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden {
    return NO; // 是否隐藏状态栏
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;

    [self doRequest];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNavigationBar];

    titleDataArray = [NSArray arrayWithObjects:@"我的支持度",@"贡献榜",@"收益",@"认证", nil];
    imageDataArray = [NSArray arrayWithObjects:@"我的支持度--图标",@"贡献榜-图标",@"收益图标",@"realNameAuth", nil];

    [self initUI];

}

- (void)setNavigationBar{
    self.navigationItem.title = @"我的";
}

- (void)initUI{

    
    __weak __typeof(self)weakSelf = self;
    myTableView = [[UITableView alloc]init];
    myTableView.showsVerticalScrollIndicator = NO;
    myTableView.showsHorizontalScrollIndicator = NO;
    myTableView.delegate = self;
    myTableView.dataSource = self;
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    myTableView.backgroundColor = UIColorFromRGBAlphaHex(0xf6f6f6, 1.0);
    myTableView.mj_header = [MJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(doRequest)];
    [self.view addSubview:myTableView];
    [myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.view.mas_left);
        make.top.equalTo(weakSelf.view.mas_top);
        make.right.equalTo(weakSelf.view.mas_right);
        make.bottom.equalTo(weakSelf.view.mas_bottom);
    }];
    
    headView = [[IVTMyCenterTableViewHead alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 355)];
    headView.delegate = self;
    myTableView.tableHeaderView = headView;
    headView.dictData = [IVTAccountTool getUserInfoAsDictionary];
}
#pragma --mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    IVTMyCenterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[IVTMyCenterTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.imageName = imageDataArray[indexPath.row];
    cell.titleString = titleDataArray[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        IVTMeSupportViewController *meSupportVC = [[IVTMeSupportViewController alloc]init];
        meSupportVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:meSupportVC animated:YES];
    }
    else if (indexPath.row == 1){
        IVTMyContributionListViewController *myContributionListVC = [[IVTMyContributionListViewController alloc]init];
        myContributionListVC.userId = [IVTAccountTool getUserId];
        myContributionListVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:myContributionListVC animated:YES];
    }
    else if (indexPath.row == 2){
        
        IVTGainsViewController * myGainsVC = [[IVTGainsViewController alloc] init];
        myGainsVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:myGainsVC animated:YES];
        
    }
    else if (indexPath.row == 3){
        RealNameAuthenticationViewController *realNameAuthenticationVC = [[RealNameAuthenticationViewController alloc]initWithNibName:@"RealNameAuthenticationViewController" bundle:nil];
        realNameAuthenticationVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:realNameAuthenticationVC animated:YES];
    }
}
#pragma --mark IVTMyCenterTableViewHeadDelegate
//设置
- (void)settingClick{
    IVTMySettingViewController *mySettingVC = [[IVTMySettingViewController alloc]init];
    mySettingVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:mySettingVC animated:YES];
}
//消息
- (void)messageClick{
    IVTMyChatListViewController *myChatListVC = [[IVTMyChatListViewController alloc]init];
    myChatListVC.isSmall = NO;
    myChatListVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:myChatListVC animated:YES];
}
//我的账号
- (void)myAccountClick{

    IVTMyAccountViewController *myAccountVC = [[IVTMyAccountViewController alloc]init];
    myAccountVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:myAccountVC animated:YES];

}
//关注
- (void)followListClick{
    IVTMyFollowListViewController *myFollowListVC = [[IVTMyFollowListViewController alloc]init];
    myFollowListVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:myFollowListVC animated:YES];
}
//粉丝
- (void)fanListClick{
    IVTMyFansListViewController *myFansListVC = [[IVTMyFansListViewController alloc]init];
    myFansListVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:myFansListVC animated:YES];
}
//进入直播
- (void)enterMyLiveClick{
    IVTMyLiveViewController *myLiveVC = [[IVTMyLiveViewController alloc]init];
    myLiveVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:myLiveVC animated:YES];
}

- (void)doRequest{
    [[IVTNetworkAPIClient sharedClient] getUserInfoOfSelfSuccess:^(NSDictionary *successData) {
        [myTableView.mj_header endRefreshing];
        NSDictionary *dict = successData[@"data"];
        headView.dictData = dict;
        
        NSMutableDictionary *dictForCache = [dict mutableCopy];
        [dictForCache setObject:[IVTAccountTool getUserName] forKey:@"msisdn"];
        [dictForCache setObject:[IVTAccountTool getPassword] forKey:@"captcha"];
        [dictForCache setObject:[NSNumber numberWithBool:NO] forKey:@"isLoginFromThirdParty"];
        [IVTAccountTool saveUserInfoToDictionary:dictForCache];
    } error:^(NSDictionary *successData) {
        [myTableView.mj_header endRefreshing];

    } failure:^(NSError *failureError) {
        [myTableView.mj_header endRefreshing];

    }];
}

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