Nenhuma Descrição

KXTeachViewController.m 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // KXTeachViewController.m
  3. // CAISHEN
  4. //
  5. // Created by kuxuan on 2017/11/1.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXTeachViewController.h"
  9. #import "KXTeachCycleView.h"
  10. #import "KXTeachCollectionViewCell.h"
  11. #import "KXNewsWebViewController.h"
  12. #import "KXCarLoancalViewController.h"
  13. @interface KXTeachViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,KXTeachCycleViewDelegate>
  14. @property (nonatomic,strong)KXTeachCycleView *teachCycle;
  15. @property (nonatomic,strong)UICollectionView *collectionView;
  16. @property (nonatomic,strong)NSMutableArray *bannnerArray;
  17. @property (nonatomic,strong)NSMutableArray *dataSource;
  18. @end
  19. @implementation KXTeachViewController
  20. {
  21. UIView *headerView;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. self.view.backgroundColor = [UIColor whiteColor];
  27. [self createCollectionView];
  28. [self requestDataSource];
  29. }
  30. - (void)createCollectionView
  31. {
  32. self.name = @"攻略";
  33. headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250)];
  34. headerView.backgroundColor = [UIColor whiteColor];
  35. UILabel *teachLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
  36. teachLabel.text = @"";
  37. teachLabel.textColor = [UIColor titleColor];
  38. teachLabel.font = FONT_SYS(16);
  39. teachLabel.textAlignment = NSTextAlignmentLeft;
  40. [headerView addSubview:teachLabel];
  41. self.teachCycle = [[KXTeachCycleView alloc]initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH - 15, 160)];
  42. self.teachCycle.delegate = self;
  43. [headerView addSubview:self.teachCycle];
  44. UILabel *grayLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 210, SCREEN_WIDTH, 5)];
  45. grayLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05];
  46. [headerView addSubview:grayLabel];
  47. UILabel *programLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 220, 100, 20)];
  48. programLabel.text = @"理财攻略";
  49. programLabel.textColor = [UIColor titleColor];
  50. programLabel.font = FONT_SYS(16);
  51. programLabel.textAlignment = NSTextAlignmentLeft;
  52. [headerView addSubview:programLabel];
  53. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  54. flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 75)/4.0, 140*SCREEN_MUTI);
  55. flowLayout.minimumLineSpacing = 10;
  56. flowLayout.minimumInteritemSpacing = 15;
  57. flowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 250);
  58. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavHeight - TabbarHeight) collectionViewLayout:flowLayout];
  59. self.collectionView.contentInset = UIEdgeInsetsMake(0, 15, 0, 15);
  60. [self.collectionView registerClass:[KXTeachCollectionViewCell class] forCellWithReuseIdentifier:@"teach"];
  61. self.collectionView.backgroundColor = [UIColor whiteColor];
  62. self.collectionView.delegate = self;
  63. self.collectionView.dataSource = self;
  64. [self.view addSubview: self.collectionView];
  65. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionViewHeader"];
  66. }
  67. #pragma mark 请求数据
  68. -(void)requestDataSource
  69. {
  70. NSString *urlString=[NSString stringWithFormat:@"%@/information/getinformationsbypackage",URL];
  71. NSDictionary *paraDict=@{@"package_id":@"package_1",@"classification_id":@"贷款",@"page":@(1)};
  72. [KXHTTP post:urlString params:paraDict success:^(id json) {
  73. NSMutableArray *bannerImageArray=[NSMutableArray arrayWithCapacity:0];
  74. if (self.bannnerArray.count==0) {
  75. for (NSDictionary *dict in json[@"ios_teach_banner"]) {
  76. [self.bannnerArray addObject:dict];
  77. [bannerImageArray addObject:dict[@"thumbnail"]];
  78. }
  79. _teachCycle.cycleArray=bannerImageArray;
  80. }
  81. NSArray *array=[NSArray yy_modelArrayWithClass:[KXNewsModel class] json:[json[@"listdata"] valueForKey:@"data"]];
  82. for (KXNewsModel *model in array) {
  83. [self.dataSource addObject:model];
  84. }
  85. [self.collectionView reloadData];
  86. } failure:^(NSError *error) {
  87. }];
  88. }
  89. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  90. {
  91. return self.dataSource.count;
  92. }
  93. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  94. {
  95. KXTeachCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"teach" forIndexPath:indexPath];
  96. KXNewsModel *model = self.dataSource[indexPath.item];
  97. cell.newsModel = model;
  98. return cell;
  99. }
  100. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  101. {
  102. NSString *CellIdentifier = @"UICollectionViewHeader";
  103. //从缓存中获取 Headercell
  104. UICollectionReusableView *cell = (UICollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  105. [cell addSubview:headerView];
  106. return cell;
  107. }
  108. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  109. {
  110. // KXNewsModel *model=self.dataSource[indexPath.item];
  111. //
  112. // KXNewsWebViewController *web=[[KXNewsWebViewController alloc]init];
  113. //
  114. // web.webID=model.Id;
  115. //
  116. // [self.navigationController pushViewController:web animated:YES];
  117. KXCarLoancalViewController *carvc = [[KXCarLoancalViewController alloc]init];
  118. [self.navigationController pushViewController:carvc animated:YES];
  119. }
  120. #pragma mark -----------------KXTeachCycleViewDelegate-----------
  121. -(void)clickScrollViewItemWithIndex:(NSInteger)index
  122. {
  123. NSDictionary *dic=self.bannnerArray[index];
  124. KXNewsWebViewController *web=[[KXNewsWebViewController alloc]init];
  125. web.webID=dic[@"id"];
  126. [self.navigationController pushViewController:web animated:YES];
  127. }
  128. -(NSMutableArray *)bannnerArray
  129. {
  130. if (!_bannnerArray) {
  131. _bannnerArray=[[NSMutableArray alloc]init];
  132. }
  133. return _bannnerArray;
  134. }
  135. - (NSMutableArray *)dataSource
  136. {
  137. if (!_dataSource) {
  138. _dataSource = [[NSMutableArray alloc]init];
  139. }
  140. return _dataSource;
  141. }
  142. - (void)didReceiveMemoryWarning {
  143. [super didReceiveMemoryWarning];
  144. // Dispose of any resources that can be recreated.
  145. }
  146. /*
  147. #pragma mark - Navigation
  148. // In a storyboard-based application, you will often want to do a little preparation before navigation
  149. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  150. // Get the new view controller using [segue destinationViewController].
  151. // Pass the selected object to the new view controller.
  152. }
  153. */
  154. @end