Aucune description

KXLoanAllViewController.m 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // KXLoanAllViewController.m
  3. // QBCS
  4. //
  5. // Created by kuxuan on 2017/6/8.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXLoanAllViewController.h"
  9. #import "KXLoanAllModel.h"
  10. #import "KXLoanAllTableViewCell.h"
  11. #import "KXLoanAllDetailViewController.h"
  12. @interface KXLoanAllViewController ()<UITableViewDelegate,UITableViewDataSource>
  13. {
  14. UITableView *_tableView;
  15. }
  16. @property (nonatomic,strong)NSMutableArray *dataSource;
  17. @property (nonatomic,strong)NSArray *otherSource;
  18. @end
  19. @implementation KXLoanAllViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.view.backgroundColor= [UIColor KXColorWithRed:239 green:239 blue:244];
  24. [self createNavigation];
  25. [self createTableView];
  26. [self requestSource];
  27. }
  28. -(void)createNavigation
  29. {
  30. self.name=@"极速贷款";
  31. [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)];
  32. }
  33. -(void)backAction
  34. {
  35. [self.navigationController popViewControllerAnimated:YES];
  36. }
  37. -(void)createTableView
  38. {
  39. _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,SCREEN_HEIGHT) style:UITableViewStylePlain];
  40. _tableView.backgroundColor= [UIColor KXColorWithRed:239 green:239 blue:244];
  41. _tableView.dataSource=self;
  42. _tableView.delegate=self;
  43. [_tableView registerClass:[KXLoanAllTableViewCell class] forCellReuseIdentifier:@"loanall"];
  44. _tableView.tableFooterView=[[UIView alloc]init];
  45. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  46. [self.view addSubview:_tableView];
  47. }
  48. -(void)requestSource
  49. {
  50. NSString *urlString=[NSString stringWithFormat:@"%@/category/list",URL];
  51. [KXHTTP post:urlString params:nil success:^(id json) {
  52. NSArray *array=[NSArray yy_modelArrayWithClass:[KXLoanAllModel class] json:json];
  53. for (KXLoanAllModel *model in array) {
  54. [self.dataSource addObject:model];
  55. }
  56. [_tableView reloadData];
  57. } failure:^(NSError *error) {
  58. }];
  59. }
  60. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  61. {
  62. return self.dataSource.count;
  63. }
  64. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. KXLoanAllModel *model=self.dataSource[indexPath.row];
  67. NSDictionary *dict=self.otherSource[indexPath.row];
  68. KXLoanAllTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
  69. if (!cell) {
  70. cell=[[KXLoanAllTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  71. }
  72. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  73. cell.model=model;
  74. cell.image=[UIImage imageNamed:dict[@"image"]];
  75. cell.backColor=dict[@"color"];
  76. return cell;
  77. }
  78. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  79. {
  80. return 80*SCREEN_MUTI;
  81. }
  82. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. KXLoanAllModel *model=self.dataSource[indexPath.row];
  85. KXLoanAllDetailViewController *detail=[[KXLoanAllDetailViewController alloc]init];
  86. detail.ID=@(model.Id.integerValue);
  87. detail.titleString=model.Description[0];
  88. [self.navigationController pushViewController:detail animated:YES];
  89. }
  90. -(NSMutableArray *)dataSource
  91. {
  92. if (!_dataSource) {
  93. _dataSource=[[NSMutableArray alloc]init];
  94. }
  95. return _dataSource;
  96. }
  97. -(NSArray *)otherSource
  98. {
  99. if (!_otherSource) {
  100. _otherSource=@[@{@"image":@"main_all_quick",@"color":[UIColor baseColor]},@{@"image":@"main_all_hot",@"color":[UIColor KXColorWithHex:0xff5a6a]},@{@"image":@"main_all_credit",@"color":[UIColor KXColorWithHex:0x57c62b]},@{@"image":@"main_all_stu",@"color":[UIColor KXColorWithHex:0xffba49]},@{@"image":@"main_all_house",@"color":[UIColor KXColorWithHex:0xc66bd6]}];
  101. }
  102. return _otherSource;
  103. }
  104. @end