口袋优选

KBFanRecommendController.m 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // KBFanRecommendController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBFanRecommendController.h"
  9. #import "KBChildFansCell.h"
  10. #import "KBChildFansModel.h"
  11. @interface KBFanRecommendController ()<UITableViewDelegate, UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) NSMutableArray *dataArr;
  14. @property (nonatomic )NSInteger page;
  15. @end
  16. @implementation KBFanRecommendController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.page=0;
  20. [self request];
  21. [self configNavigationBar];
  22. [self configTableView];
  23. }
  24. - (void)configTableView {
  25. [self.view addSubview:self.tableView];
  26. }
  27. - (void)configNavigationBar {
  28. [self.navigationBar setNavTitle:[NSString stringWithFormat:@"%@的推荐",self.userName]];
  29. self.navigationBar.backgroundColor = [UIColor changeColor];
  30. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  31. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  32. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  33. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  34. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  35. }
  36. - (void)backAction {
  37. [self.navigationController popViewControllerAnimated:YES];
  38. }
  39. #pragma mark - request
  40. - (void)request {
  41. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/oneFansList",BaseURL];
  42. self.page ++;
  43. NSDictionary *dic=@{
  44. @"user_id":self.userId,
  45. @"page":@(self.page)
  46. };
  47. [KBHttp post:url params:dic success:^(id json) {
  48. NSArray *arr = [NSArray yy_modelArrayWithClass:[KBChildFansModel class] json:json[@"data"]];
  49. if (arr.count>0) {
  50. [self.dataArr addObjectsFromArray:arr];
  51. }else {
  52. [self setUpNoDataView];
  53. [self noMoreDataWithArray:arr];
  54. }
  55. [self.tableView reloadData];
  56. [self.tableView.mj_footer endRefreshing];
  57. } failure:^(NSError *error) {
  58. [self.tableView.mj_footer endRefreshing];
  59. }];
  60. }
  61. - (void)setUpNoDataView {
  62. self.tableView.showNoDataView = YES;
  63. self.tableView.defaultNoDataText = @"您还没有任何记录";
  64. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  65. }
  66. - (void)noMoreDataWithArray:(NSArray *)array {
  67. if (array.count > 0) {
  68. self.tableView.footRefreshState = MJTableFooterRefreshStateLoadMore;
  69. }else {
  70. self.tableView.footRefreshState = MJTableFooterRefreshStateNoMore;
  71. }
  72. }
  73. #pragma mark -------- UITableView Delegate -----
  74. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  75. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  76. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  77. }
  78. }
  79. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  80. return self.dataArr.count;
  81. }
  82. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  83. return 67;
  84. }
  85. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  86. return 0.1;
  87. }
  88. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  89. return 0.1;
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  92. KBChildFansCell *cell = [KBChildFansCell cellWithTableView:tableView];
  93. KBChildFansModel *model=self.dataArr[indexPath.row];
  94. cell.model=model;
  95. cell.updateBtn.hidden = YES;
  96. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  97. return cell;
  98. }
  99. #pragma mark ------- layzer ------
  100. - (UITableView *)tableView {
  101. if (!_tableView) {
  102. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStylePlain];
  103. _tableView.estimatedSectionHeaderHeight = 0;
  104. _tableView.estimatedSectionFooterHeight = 0;
  105. _tableView.sectionFooterHeight = 0;
  106. _tableView.sectionHeaderHeight = 0;
  107. _tableView.delegate = self;
  108. _tableView.dataSource = self;
  109. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  110. _tableView.backgroundColor = [UIColor yhGrayColor];
  111. _tableView.bounces = YES;
  112. _tableView.showsVerticalScrollIndicator = NO;
  113. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  114. kWeak(self);
  115. _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  116. [selfWeak request];
  117. }];
  118. _tableView.footRefreshState = MJTableFooterRefreshStateNormal;
  119. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  120. _tableView.bounces = NO;
  121. }
  122. return _tableView;
  123. }
  124. - (void)didReceiveMemoryWarning {
  125. [super didReceiveMemoryWarning];
  126. // Dispose of any resources that can be recreated.
  127. }
  128. -(NSMutableArray *)dataArr{
  129. if (!_dataArr) {
  130. _dataArr=[NSMutableArray array];
  131. }
  132. return _dataArr;
  133. }
  134. @end