// // KXLoanAllViewController.m // QBCS // // Created by kuxuan on 2017/6/8. // Copyright © 2017年 kuxuan. All rights reserved. // #import "KXLoanAllViewController.h" #import "KXLoanAllModel.h" #import "KXLoanAllTableViewCell.h" #import "KXLoanAllDetailViewController.h" @interface KXLoanAllViewController () { UITableView *_tableView; } @property (nonatomic,strong)NSMutableArray *dataSource; @property (nonatomic,strong)NSArray *otherSource; @end @implementation KXLoanAllViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor= [UIColor KXColorWithRed:239 green:239 blue:244]; [self createNavigation]; [self createTableView]; [self requestSource]; } -(void)createNavigation { self.name=@"极速贷款"; [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)]; } -(void)backAction { [self.navigationController popViewControllerAnimated:YES]; } -(void)createTableView { _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,SCREEN_HEIGHT) style:UITableViewStylePlain]; _tableView.backgroundColor= [UIColor KXColorWithRed:239 green:239 blue:244]; _tableView.dataSource=self; _tableView.delegate=self; [_tableView registerClass:[KXLoanAllTableViewCell class] forCellReuseIdentifier:@"loanall"]; _tableView.tableFooterView=[[UIView alloc]init]; _tableView.separatorStyle=UITableViewCellSeparatorStyleNone; [self.view addSubview:_tableView]; } -(void)requestSource { NSString *urlString=[NSString stringWithFormat:@"%@/category/list",URL]; [KXHTTP post:urlString params:nil success:^(id json) { NSArray *array=[NSArray yy_modelArrayWithClass:[KXLoanAllModel class] json:json]; for (KXLoanAllModel *model in array) { [self.dataSource addObject:model]; } [_tableView reloadData]; } failure:^(NSError *error) { }]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataSource.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KXLoanAllModel *model=self.dataSource[indexPath.row]; NSDictionary *dict=self.otherSource[indexPath.row]; KXLoanAllTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell=[[KXLoanAllTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.selectionStyle=UITableViewCellSelectionStyleNone; cell.model=model; cell.image=[UIImage imageNamed:dict[@"image"]]; cell.backColor=dict[@"color"]; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 80*SCREEN_MUTI; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { KXLoanAllModel *model=self.dataSource[indexPath.row]; KXLoanAllDetailViewController *detail=[[KXLoanAllDetailViewController alloc]init]; detail.ID=@(model.Id.integerValue); detail.titleString=model.Description[0]; [self.navigationController pushViewController:detail animated:YES]; } -(NSMutableArray *)dataSource { if (!_dataSource) { _dataSource=[[NSMutableArray alloc]init]; } return _dataSource; } -(NSArray *)otherSource { if (!_otherSource) { _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]}]; } return _otherSource; } @end