No Description

KXLoanAllDetailViewController.m 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // KXLoanAllDetailViewController.m
  3. // QBCS
  4. //
  5. // Created by kuxuan on 2017/6/8.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXLoanAllDetailViewController.h"
  9. #import "KXMainListTableViewCell.h"
  10. #import "KXHotList.h"
  11. #import "KXMainDetailViewController.h"
  12. #import "KXMainDetailModel.h"
  13. #import "KXWebDetailViewController.h"
  14. @interface KXLoanAllDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
  15. @property (nonatomic,strong)UITableView *tableView;
  16. @property (nonatomic,strong)NSMutableArray *dataSource;
  17. @property (nonatomic,assign)NSInteger page;
  18. @end
  19. @implementation KXLoanAllDetailViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.page=1;
  24. [self createNavigationBar];
  25. [self createTabletableView];
  26. }
  27. -(void)createNavigationBar
  28. {
  29. self.name=self.titleString;
  30. [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)];
  31. }
  32. -(void)backAction
  33. {
  34. self.changeLabel();
  35. [self.navigationController popViewControllerAnimated:YES];
  36. }
  37. -(void)createTabletableView
  38. {
  39. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeight-safeBottomHeight) style:UITableViewStylePlain];
  40. self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  41. [self.tableView registerClass:[KXMainListTableViewCell class] forCellReuseIdentifier:@"main"];
  42. self.tableView.tableFooterView=[[UIView alloc]init];
  43. //下拉刷新
  44. MJRefreshNormalHeader *header =
  45. [[MJRefreshNormalHeader alloc]init];
  46. [header setRefreshingTarget:self refreshingAction:@selector(refreshHeader:)];
  47. self.tableView.mj_header = header;
  48. [header beginRefreshing];
  49. //上拉加载
  50. MJRefreshAutoNormalFooter *footer=[[MJRefreshAutoNormalFooter alloc]init];
  51. [footer setRefreshingTarget:self refreshingAction:@selector(refreshFooter:)];
  52. self.tableView.mj_footer=footer;
  53. self.tableView.delegate = self;
  54. self.tableView.dataSource = self;
  55. [self.view addSubview:self.tableView];
  56. header.stateLabel.font = FONT_SYS(14);
  57. header.stateLabel.textColor=[UIColor detailTitleColor];
  58. header.lastUpdatedTimeLabel.font=FONT_SYS(14);
  59. header.lastUpdatedTimeLabel.textColor=[UIColor detailTitleColor];
  60. footer.stateLabel.textColor=[UIColor detailTitleColor];
  61. }
  62. #pragma mark 下拉刷新和上拉加载
  63. -(void)refreshHeader:(MJRefreshHeader *)header
  64. {
  65. self.page=1;
  66. [self requestDataWithPage:self.page];
  67. }
  68. -(void)refreshFooter:(MJRefreshAutoFooter *)footer
  69. {
  70. self.page++;
  71. [self requestDataWithPage:self.page];
  72. }
  73. -(void)requestDataWithPage:(NSInteger)page
  74. {
  75. NSString *urlString=[NSString stringWithFormat:@"%@/product/getInfoByCat",URL];
  76. [KXHTTP post:urlString params:@{@"id":self.ID,@"page":@(page)} success:^(id json) {
  77. NSArray *array=[NSArray yy_modelArrayWithClass:[KXHotList class] json:json[@"data"]];
  78. if (self.page==1) {
  79. [self.dataSource removeAllObjects];
  80. }
  81. for (KXHotList *model in array) {
  82. [self.dataSource addObject:model];
  83. }
  84. if (array.count < 10) {
  85. [_tableView.mj_header endRefreshing];
  86. [_tableView.mj_footer endRefreshing];
  87. [_tableView.mj_footer endRefreshingWithNoMoreData];
  88. }else{
  89. [_tableView.mj_header endRefreshing];
  90. [_tableView.mj_footer endRefreshing];
  91. }
  92. [_tableView reloadData];
  93. } failure:^(NSError *error) {
  94. }];
  95. }
  96. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  97. {
  98. return self.dataSource.count;
  99. }
  100. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  101. {
  102. KXHotList *model=self.dataSource[indexPath.row];
  103. KXMainListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"main"];
  104. if (!cell) {
  105. cell=[[KXMainListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"main"];
  106. }
  107. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  108. // cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
  109. cell.hotmodel=model;
  110. return cell;
  111. }
  112. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. return 80*SCREEN_MUTI;
  115. }
  116. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  117. {
  118. KXHotList *model=self.dataSource[indexPath.row];
  119. //0跳详情,1跳链接
  120. if ([model.skip_type isEqualToString:@"1"]) {
  121. KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
  122. web.webStr=model.link;
  123. web.titleStr = model.name;
  124. web.product_id = model.Id;
  125. web.product_apply_id = @"0";
  126. [self.navigationController pushViewController:web animated:YES];
  127. }else{
  128. KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
  129. detail.detailID=model.Id;
  130. detail.titleString=model.name;
  131. if ([self.titleString isEqualToString:@"极速贷"]) {
  132. detail.enterSource = @"speedKind";
  133. } else if ([self.titleString isEqualToString:@"热门贷"])
  134. {
  135. detail.enterSource = @"hotKind";
  136. } else if ([self.titleString isEqualToString:@"信用贷"])
  137. {
  138. detail.enterSource = @"creditKind";
  139. } else if ([self.titleString isEqualToString:@"大额贷"])
  140. {
  141. detail.enterSource = @"LargeAmount_kind";
  142. }
  143. [self.navigationController pushViewController:detail animated:YES];
  144. }
  145. }
  146. #pragma mark lazyload
  147. -(NSMutableArray *)dataSource
  148. {
  149. if (!_dataSource) {
  150. _dataSource=[[NSMutableArray alloc]init];
  151. }
  152. return _dataSource;
  153. }
  154. @end