IVTMyFansListViewController.m 4.58 KB
//
//  IVTMyFansListViewController.m
//  IVTMeLiveTwo
//
//  Created by XRG on 16/8/23.
//  Copyright © 2016年 QLQ. All rights reserved.
//

#import "IVTMyFansListViewController.h"
#import "IVTMyFollowListTableViewCell.h"
#import "IVTUserInfoCenterViewController.h"

@interface IVTMyFansListViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray *myFansListArray;
    UITableView *myTableView;
    UILabel *noDataLabel;

}
@end

@implementation IVTMyFansListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavigationBar];

    
    __weak __typeof(self)weakSelf = self;

    myTableView = [[UITableView alloc] init];
    myTableView.backgroundColor = [UIColor IVTBackgroundColor];
    myTableView.delegate = self;
    myTableView.dataSource = self;
    myTableView.showsHorizontalScrollIndicator = NO;
    myTableView.showsVerticalScrollIndicator = NO;
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [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);
    }];
    
    noDataLabel = [[UILabel alloc]init];
    noDataLabel.font = [UIFont systemFontOfSize:13];
    noDataLabel.frame = CGRectMake(kScreenWidth / 2 - 100, kScreenWidth / 2 + 50, 200, 100);
    noDataLabel.text = @"没有数据";
    noDataLabel.hidden = YES;
    noDataLabel.font = [UIFont systemFontOfSize:16];
    noDataLabel.text = @"空空如也~~";
    noDataLabel.textAlignment = 1;
    [self.view addSubview:noDataLabel];
    myFansListArray = [[NSMutableArray alloc]initWithCapacity:10];

    myTableView.mj_header= [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(doRequest)];
    [myTableView.mj_header beginRefreshing];
}

- (void)doRequest{
    [[IVTNetworkAPIClient sharedClient] getFansListSuccess:^(NSDictionary *successData) {
        [myFansListArray removeAllObjects];

        [myFansListArray addObjectsFromArray:successData[@"data"]];
        
        [myTableView.mj_header endRefreshing];
        
        if (myFansListArray.count == 0) {
            noDataLabel.hidden = NO;
        }
        else{
            noDataLabel.hidden = YES;
            
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [myTableView reloadData];
        });
    } error:^(NSDictionary *successData) {
        [myTableView.mj_header endRefreshing];
        NSString *msg = successData[@"description"];
        [HUDUtil showError:msg];
    } failure:^(NSError *failureError) {
        [myTableView.mj_header endRefreshing];
        [HUDUtil showError:@"网络异常"];

    }];
}


- (void)setNavigationBar{
    self.navigationItem.title = @"粉丝";
}

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    IVTMyFollowListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[IVTMyFollowListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.entity = [myFansListArray objectAtIndex:indexPath.row];
    
    return cell;
}

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    IVTUserInfoCenterViewController *userInfoCenterVC = [[IVTUserInfoCenterViewController alloc]init];
    userInfoCenterVC.userId = [NSString stringWithFormat:@"%ld",[[[myFansListArray objectAtIndex:indexPath.row] valueForKey:@"id"] integerValue]];
    [self.navigationController pushViewController:userInfoCenterVC animated:YES];
}



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