猎豆优选

LDFanRecommendController.m 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // LDFanRecommendController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDFanRecommendController.h"
  9. #import "LDChildFansCell.h"
  10. #import "LDChildFansModel.h"
  11. @interface LDFanRecommendController ()<UITableViewDelegate, UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) NSMutableArray *dataArr;
  14. @property (nonatomic )NSInteger page;
  15. @end
  16. @implementation LDFanRecommendController
  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. [LDHttp post:url params:dic success:^(id json) {
  48. NSArray *arr = [NSArray yy_modelArrayWithClass:[LDChildFansModel class] json:json[@"data"]];
  49. if (arr.count>0) {
  50. [self.dataArr addObjectsFromArray:arr];
  51. }else {
  52. [self setUpNoDataView];
  53. }
  54. [self noMoreDataWithArray:arr];
  55. [self.tableView reloadData];
  56. } failure:^(NSError *error) {
  57. [self.tableView.mj_footer endRefreshing];
  58. }];
  59. }
  60. - (void)setUpNoDataView {
  61. self.tableView.showNoDataView = YES;
  62. self.tableView.defaultNoDataText = @"您还没有任何记录";
  63. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  64. }
  65. - (void)noMoreDataWithArray:(NSArray *)array {
  66. if (array.count > 0) {
  67. [self.tableView.mj_footer endRefreshing];
  68. }else {
  69. [self.tableView.mj_footer endRefreshingWithNoMoreData];;
  70. }
  71. }
  72. #pragma mark -------- UITableView Delegate -----
  73. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  74. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  75. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  76. }
  77. }
  78. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  79. return self.dataArr.count;
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  82. return 67;
  83. }
  84. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  85. return 0.1;
  86. }
  87. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  88. return 0.1;
  89. }
  90. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  91. LDChildFansCell *cell = [LDChildFansCell cellWithTableView:tableView];
  92. cell.cellType = -1;
  93. LDChildFansModel *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 = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  116. [selfWeak request];
  117. }];
  118. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  119. }
  120. return _tableView;
  121. }
  122. - (void)didReceiveMemoryWarning {
  123. [super didReceiveMemoryWarning];
  124. // Dispose of any resources that can be recreated.
  125. }
  126. -(NSMutableArray *)dataArr{
  127. if (!_dataArr) {
  128. _dataArr=[NSMutableArray array];
  129. }
  130. return _dataArr;
  131. }
  132. @end