// // KBFanRecommendController.m // YouHuiProject // // Created by 小花 on 2018/5/21. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBFanRecommendController.h" #import "KBChildFansCell.h" #import "KBChildFansModel.h" @interface KBFanRecommendController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *dataArr; @property (nonatomic )NSInteger page; @end @implementation KBFanRecommendController - (void)viewDidLoad { [super viewDidLoad]; self.page=0; [self request]; [self configNavigationBar]; [self configTableView]; } - (void)configTableView { [self.view addSubview:self.tableView]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@的推荐",self.userName]]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } #pragma mark - request - (void)request { NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/oneFansList",BaseURL]; self.page ++; NSDictionary *dic=@{ @"user_id":self.userId, @"page":@(self.page) }; [KBHttp post:url params:dic success:^(id json) { NSArray *arr = [NSArray yy_modelArrayWithClass:[KBChildFansModel class] json:json[@"data"]]; if (arr.count>0) { [self.dataArr addObjectsFromArray:arr]; }else { [self setUpNoDataView]; [self noMoreDataWithArray:arr]; } [self.tableView reloadData]; [self.tableView.mj_footer endRefreshing]; } failure:^(NSError *error) { [self.tableView.mj_footer endRefreshing]; }]; } - (void)setUpNoDataView { self.tableView.showNoDataView = YES; self.tableView.defaultNoDataText = @"您还没有任何记录"; self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"]; } - (void)noMoreDataWithArray:(NSArray *)array { if (array.count > 0) { self.tableView.footRefreshState = MJTableFooterRefreshStateLoadMore; }else { self.tableView.footRefreshState = MJTableFooterRefreshStateNoMore; } } #pragma mark -------- UITableView Delegate ----- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 67; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.1; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KBChildFansCell *cell = [KBChildFansCell cellWithTableView:tableView]; KBChildFansModel *model=self.dataArr[indexPath.row]; cell.model=model; cell.updateBtn.hidden = YES; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } #pragma mark ------- layzer ------ - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStylePlain]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = YES; _tableView.showsVerticalScrollIndicator = NO; _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; kWeak(self); _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ [selfWeak request]; }]; _tableView.footRefreshState = MJTableFooterRefreshStateNormal; _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE]; _tableView.bounces = NO; } return _tableView; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSMutableArray *)dataArr{ if (!_dataArr) { _dataArr=[NSMutableArray array]; } return _dataArr; } @end